#include #include #include #include bool judge(const std::vector& xs) { int n = xs.size() / 3; std::vector> idxs(n, std::vector(3, -1)); bool ret = true; for (int i = 0; i < (int)xs.size(); ++i) { if (xs[i] == -1) continue; auto& is = idxs[xs[i]]; for (int j = 0; j < 3; ++j) { if (is[j] == -1) { is[j] = i; break; } } if (is.back() == -1) continue; auto d = std::abs((is[1] - is[0]) - (is[2] - is[1])); if (d != xs[i]) { ret = false; break; } } return ret; } std::vector brute_normal(int n) { std::vector xs(n * 3); for (int i = 0; i < n; ++i) { for (int j = 0; j < 3; ++j) { xs[i * 3 + j] = i; } } do { if (judge(xs)) return xs; } while (std::next_permutation(xs.begin(), xs.end())); std::terminate(); } std::vector brute_sep(int n) { std::vector xs(n * 3); for (int i = 0; i < n; ++i) { for (int j = 0; j < 3; ++j) { xs[i * 3 + j] = i; } } xs.insert(xs.begin() + 1, -1); do { if (xs[1] == -1 && judge(xs)) return xs; } while (std::next_permutation(xs.begin(), xs.end())); std::terminate(); } void solve() { int n; std::cin >> n; if (n == 2) { std::cout << -1 << std::endl; return; } int l = 0, r = n * 3 - 1; std::vector ans(n * 3, -1); bool sep = false; while (n > 5) { if (!sep) { if (n % 2 != 0) { // 665544654... for (int x = n - 1; x >= n / 2; --x) { ans[l] = ans[l + 1] = ans[l + x + 2] = x; l += 2; } l += n - n / 2; n = n / 2; } else { // 77665544376543.3... for (int x = n - 1; x >= n / 2; --x) { ans[l] = ans[l + 1] = ans[l + 1 + x + 1] = x; l += 2; } { int x = n / 2 - 1; ans[l] = ans[l + x + 2] = ans[l + x + 4] = x; l += 1; } l += n - (n / 2 - 1); n = n / 2 - 1; sep = true; } } else { if (n % 2 != 0) { // ...456445566 for (int x = n - 1; x >= n / 2; --x) { ans[r] = ans[r - 1] = ans[r - x - 2] = x; r -= 2; } r -= n - n / 2; n = n / 2; } else { // 7x66554477654... ans[l] = ans[l + n] = ans[l + n + 1] = n - 1; l += 2; for (int x = n - 2; x >= n / 2; --x) { ans[l] = ans[l + 1] = ans[l + 1 + x + 1] = x; l += 2; } l += n - n / 2 + 1; n = n / 2; sep = false; } } } auto sol = (sep ? brute_sep(n) : brute_normal(n)); for (auto x : sol) { if (x != -1) ans[l] = x; ++l; } for (auto a : ans) std::cout << a << " "; std::cout << "\n"; assert(judge(ans)); } int main() { solve(); return 0; }