Under construction

Still being built. Things may change

NL-Queen (mod N)

Time limit2sMemory limit1024 MB

Summary
Place N queens on an N by N board whose opposite edges connect, so none attack each other, and print one placement that is not k-linear, or -1 if impossible.
Level

Hard8 of 10

Topics
Math, Implementation
Solved
No attempts yet

Problem

Given an N×NN \times N chessboard, print one special way to place NN queens so that no two queens attack each other. The square in row rr and column cc is (r,c)(r, c). The top-left square is (1,1)(1, 1) and the bottom-right square is (N,N)(N, N). Opposite edges of the board are connected, so the board wraps around. Two queens at (a,b)(a, b) and (c,d)(c, d) attack each other if at least one of the following four conditions holds.

  1. a=ca = c
  2. b=db = d
  3. a+b≡c+d(modN)a+b \equiv c+d \pmod N
  4. a−b≡c−d(modN)a-b \equiv c-d \pmod N

In a placement where no two queens attack each other, let AiA_i be the column of the queen in row ii. If an integer kk satisfies A(i mod N)+1−Ai≡k(modN)A_{(i \bmod N) + 1} - A_i \equiv k \pmod N for every ii, the placement is called kk-linear. If the placement is not kk-linear for any integer kk, it is called special.

Input

The first line contains an integer NN. (2≤N≤500 0002 \le N \le 500\,000)

Output

If NN queens can be placed, print A1,A2,A3,⋯ ,ANA_1, A_2, A_3, \cdots, A_N on the first line. (1≤Ai≤N1 \le A_i \le N)

If NN queens cannot be placed, print -1.

Examples3

  1. Example 1

    Input
    2
    
    Expected output
    -1
    
  2. Example 2

    Input
    5
    
    Expected output
    -1
    
  3. Example 3

    Input
    25
    
    Expected output
    7 1 3 13 20 4 14 16 23 2 15 8 6 24 12 18 22 5 10 21 9 25 17 19 11