Cyclic Antimonotonic Permutations

No attempts yetTime limit2sMemory limit128 MB

Problem

A permutation is a sequence of integers in which each integer from $1$ to $n$ appears exactly once. In this problem we look for permutations $p_1, p_2, \dots, p_n$ that satisfy both of the following properties:

  1. Antimonotonic: for every position $i$ with $1 < i < n$, the value $p_i$ must be either the smallest or the largest among the three neighbouring values $p_{i-1}, p_i, p_{i+1}$.
  2. Cyclic: treat each $p_i$ as a pointer leading from position $i$ to position $p_i$. Starting at position $1$ and following the pointers, you must be able to reach all $n$ positions before returning to position $1$; that is, the permutation must consist of a single cycle of length $n$.

Input

The input consists of several test cases. Each test case is a single line containing one integer $n$ ($3 \le n \le 10^6$), the length of the permutation. The input is terminated by a line with $n = 0$, which is not processed.

Output

For each test case, print on its own line the lexicographically smallest permutation of the integers $1$ to $n$ that is both antimonotonic and cyclic. To compare two permutations $a$ and $b$, compare the sequences $a_1, a_2, \dots, a_n$ and $b_1, b_2, \dots, b_n$ from left to right; the permutation with the smaller value at the first position where they differ is the smaller one. Separate the integers on a line with single spaces.