Account
GitHubFeedback
Drafts and results saved on this device
Submit on CSES.fi
CSES Problemset/Introductory Problems

Permutations

#1070
Ask AI

Open a hint-first prompt in a new AI chat. Grok may ask you to confirm before sending.

Open Claude Desktop

Time limit:1.00 s
Memory limit:512 MB
Unsolved
Download Tests (.zip)

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

Given nn, construct a beautiful permutation if such a permutation exists.

Input

The only input line contains an integer nn.

Output

Print a beautiful permutation of integers 1,2,…,n1,2,\ldots,n. If there are several solutions, you may print any of them. If there are no solutions, print "NO SOLUTION".

Constraints
  • 1≤n≤1061 \le n \le 10^6
Sample Test Cases (2)
Example 1ID: sample-1
Input
5
Expected Output
4 2 5 3 1
Example 2ID: sample-2
Input
3
Expected Output
NO SOLUTION
Tools
1
2
3
4
5
6
7
8
9
10
11
12
Draft saved locally
|1 line, 0 chars
Test Bench
Download .zip
Input (stdin)
5
Expected Output
4 2 5 3 1