import std.conv, std.functional, std.range, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; } int readInt() { return readToken.to!int; } long readLong() { return readToken.to!long; } real readReal() { return readToken.to!real; } bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } } bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } } int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; } int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); } int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); } void main() { /* debug { foreach (n; 1 .. 10 + 1) { int[] perm; foreach (i; 0 .. n) { perm ~= i; perm ~= i; perm ~= i; } do { auto poss = new int[][n]; foreach (i; 0 .. n * 3) { // poss[perm[i]] ~= i; poss[perm[i]] ~= ((i == n * 3 - 1) ? (n * 3) : i); } bool ok = true; foreach (j; 0 .. n) { ok = ok && (abs((poss[j][1] - poss[j][0] - 1) - (poss[j][2] - poss[j][1] - 1)) == j); } if (ok) { writeln(perm); stdout.flush; break; } } while (perm.nextPermutation); } } //*/ /* [0, 0, 0] [0, 0, 0, 1, 2, 1, 1, 2, 2] [0, 0, 0, 1, 1, 3, 1, 2, 2, 3, 3, 2] [0, 0, 0, 1, 1, 2, 1, 3, 4, 4, 2, 3, 3, 2, 4] [0, 0, 0, 1, 1, 2, 1, 2, 3, 4, 5, 2, 3, 3, 4, 4, 5, 5] [0, 0, 0, 1, 1, 1] [0, 0, 0, 2, 1, 2, 1, 1, 2] [0, 0, 0, 1, 2, 3, 1, 2, 1, 3, 3, 2] [0, 0, 0, 1, 1, 2, 1, 2, 3, 4, 4, 2, 3, 3, 4] [0, 0, 0, 1, 1, 2, 1, 3, 2, 3, 4, 5, 5, 2, 3, 4, 4, 5] */ try { for (; ; ) { const N = readInt(); if (N == 2) { writeln(-1); continue; } int[] fs, gs; for (int a = N - 1; ; ) { if (gs.length % 2 == 0) { if (a == 0 || a == 2 || a == 3 || a == 4 || a == 5) { fs ~= a; break; } } else { if (a == 1 || a == 2 || a == 3 || a == 4 || a == 5) { gs ~= a; break; } } if (a % 2 == 0) { fs ~= a; } else { gs ~= a; } a = a / 2 - 1; } debug { writeln("fs = ", fs); writeln("gs = ", gs); } int[] ans; foreach (f; fs) { switch (f) { case 0: ans ~= [0, 0, 0]; break; case 2: ans ~= [0, 0, 0, 1, 2, 1, 1, 2, 2]; break; case 3: ans ~= [0, 0, 0, 1, 1, 3, 1, 2, 2, 3, 3, 2]; break; case 4: ans ~= [0, 0, 0, 1, 1, 2, 1, 3, 4, 4, 2, 3, 3, 2, 4]; break; case 5: ans ~= [0, 0, 0, 1, 1, 2, 1, 2, 3, 4, 5, 2, 3, 3, 4, 4, 5, 5]; break; default: { foreach_reverse (i; f / 2 .. f + 1) { ans ~= i; ans ~= i; } foreach_reverse (i; f / 2 .. f + 1) { ans ~= i; } } } } foreach (j, g; gs) { const head = cast(int)(ans.length); switch (g) { case 1: ans ~= [0, 0, 0, 1, 1, 1]; break; case 2: ans ~= [0, 0, 0, 2, 1, 2, 1, 1, 2]; break; case 3: ans ~= [0, 0, 0, 1, 2, 3, 1, 2, 1, 3, 3, 2]; break; case 4: ans ~= [0, 0, 0, 1, 1, 2, 1, 2, 3, 4, 4, 2, 3, 3, 4]; break; case 5: ans ~= [0, 0, 0, 1, 1, 2, 1, 3, 2, 3, 4, 5, 5, 2, 3, 4, 4, 5]; break; default: { foreach_reverse (i; g / 2 + 1 .. g + 1) { ans ~= i; ans ~= i; } ans ~= g / 2; foreach_reverse (i; g / 2 + 1 .. g + 1) { ans ~= i; } ans ~= g / 2; ans ~= g / 2; } } const tail = cast(int)(ans.length); if (j % 2 != 0) { ans[head .. tail].reverse; swap(ans[head - 1], ans[head]); } } assert(ans.length == N * 3); foreach (j; 0 .. N * 3) { if (j > 0) write(" "); write(ans[j]); } writeln(); auto poss = new int[][N]; foreach (j; 0 .. N * 3) { poss[ans[j]] ~= j; } foreach (j; 0 .. N) { assert(abs((poss[j][1] - poss[j][0] - 1) - (poss[j][2] - poss[j][1] - 1)) == j); } } } catch (EOFException e) { } }