7020.Beautiful Permutation II

Time Limit: 1s Memory Limit: 512MB

A permutation of integers $1,2,\ldots,n$ is called beautiful if there are no adjacent elements whose difference is $1$ .

Given $n$ , construct the lexicographically minimal beautiful permutation if such a permutation exists.

Input Format(From the terminal/stdin)

The only line contains an integer $n$ .

  • $1 \le n \le 10^6$

Output Format(To the terminal/stdout)

Print the lexicographically minimal beautiful permutation of integers $1,2,\ldots,n$ . If there is no such permutation, print "NO SOLUTION".

Sample Input 1

Copy
5
 \n

Sample Output 1

Copy
1 3 5 2 4
 · · · · \n

Sample Input 2

Copy
3
 \n

Sample Output 2

Copy
NO SOLUTION
  ·        \n
Source: CSES, Additional Problems I, 3175

Submit

请先 登录

© 2025 FAQs