Under construction

Still being built. Things may change

Mars Car Numbers

Interview

Time limit1sMemory limit1024 MB

Summary
Given N, find the lexicographically largest permutation in the first half and the smallest in the second half of all permutations of 1 to N.
Level

Medium5 of 10

Topics
Combinatorics, Implementation
Solved
No attempts yet

Statement

Mars is introducing a new car number system. In this system, each number plate is a permutation of NN, that is, a sequence in which each of the numbers 1…N1 \ldots N appears exactly once.

For administrative purposes, Mars is divided into a southern and a northern hemisphere. So that a car's number shows which hemisphere it comes from, the southern hemisphere uses the N!/2N!/2 lexicographically smallest plates, and the northern hemisphere uses the N!/2N!/2 lexicographically largest plates.

The governors want special numbers. The southern governor takes the lexicographically largest number among the plates of the southern hemisphere, and the northern governor takes the lexicographically smallest number among the plates of the northern hemisphere.

Write a program that finds the numbers the two governors receive.

N!N! denotes the product 1⋅2⋅…⋅N1 \cdot 2 \cdot \ldots \cdot N. A sequence a=(a1,a2,…,an)a = (a_1, a_2, \ldots, a_n) is lexicographically smaller than b=(b1,b2,…,bn)b = (b_1, b_2, \ldots, b_n) if, for some index tt, a1=b1a_1 = b_1, a2=b2a_2 = b_2, \ldots, at=bta_t = b_t and at+1<bt+1a_{t+1} < b_{t+1}.

Input

The only line of the text file contains an integer NN (2≤N≤5⋅1052 \le N \le 5 \cdot 10^5), the length of the Mars car numbers.

Output

The text file must contain exactly two lines, each with NN integers separated by spaces. The first line is the number of the southern governor's car, and the second line is the number of the northern governor's car.

Examples2

  1. Example 1

    Input
    2
    
    Expected output
    1 2
    2 1
    
  2. Example 2

    Input
    3
    
    Expected output
    2 1 3
    2 3 1