Problems > Beautiful Permutation

Beautiful Permutation

Difficulty: 1300 2000 ms 128 MB

math implementation

Output a permutation of 1..N where no two adjacent values differ by exactly 1 — specifically, print all EVEN numbers ascending, then all ODD numbers ascending. If no such permutation exists (N = 2 or 3), print NO SOLUTION.

Input: one integer N.

Output: the required permutation, or NO SOLUTION.

Constraints:

  • 1 ≤ N ≤ 105

Sample Tests

Input 1
5
Output 1
2 4 1 3 5
Input 2
3
Output 2
NO SOLUTION

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.