#C3053. Construct Lexicographically Smallest List

    ID: 46438 Type: Default 1000ms 256MiB

Construct Lexicographically Smallest List

Construct Lexicographically Smallest List

You are given two integers \(N\) and \(K\). Your task is to construct a list of distinct integers from \(1\) to \(N\) such that:

  • The sum of the list is divisible by \(K\). In other words, if \(S = 1 + 2 + \cdots + N = \frac{N(N+1)}{2}\), then \(K\) should divide \(S\) (i.e. \(S \equiv 0 \pmod{K}\)).
  • The difference between the maximum and minimum elements is minimized. Note that since the list comprises all numbers from 1 to \(N\), this difference is always \(N - 1\).
  • If multiple solutions exist, you should output the lexicographically smallest list.

If such a list exists, output the list. Otherwise, output -1.

Note: The list, if it exists, is always [1, 2, 3, \(\dots\), N] if \(\frac{N(N+1)}{2}\) is divisible by \(K\), because this is the only possible candidate that minimizes the difference and is lexicographically smallest.

Examples:

Input: 10 5
Output: 1 2 3 4 5 6 7 8 9 10

Input: 10 4 Output: -1

</p>

inputFormat

The input is read from stdin and consists of a single line containing two integers \(N\) and \(K\) separated by space.

\(N\) represents the upper bound of the sequence (from 1 to \(N\)) and \(K\) is the divisor.

outputFormat

If a valid list exists, output \(N\) space-separated integers on a single line (the list from 1 to \(N\)). Otherwise, output -1.

Output to stdout.

## sample
10 5
1 2 3 4 5 6 7 8 9 10