#K38772. Deranged Sequence Generation

    ID: 26273 Type: Default 1000ms 256MiB

Deranged Sequence Generation

Deranged Sequence Generation

You are given a positive integer N. Your task is to generate a permutation of the integers from 1 to N such that for almost every position i (with the exception allowed when N is odd, where the last element may remain unchanged), the condition \(a_i \neq i\) holds. In other words, for all valid indices i (except possibly the last one in the case of odd N), the element at that position should not be equal to i. If it is impossible to generate such a permutation (which is the case when N = 1), print an empty output.

Note: For a valid permutation sequence \(a_1, a_2, \dots, a_N\), the condition is:

[ \text{For } 1 \leq i \leq N ; (\text{or for } 1 \leq i < N \text{ if } N \text{ is odd}), \quad a_i \neq i. ]

inputFormat

The input consists of a single integer N (read from standard input) which represents the length of the sequence.

outputFormat

If a valid permutation exists, output the sequence of N integers separated by a space on one line (written to standard output). If it is impossible to generate such a permutation (i.e. when N = 1), output nothing (an empty line).

## sample
4
2 1 4 3

</p>