cho.sh
Notes
Loading...

Balance Scale

Time limit

1s

Memory limit

512 MB

Problem

There is one weight numbered 1 through n. The weight of each item is equal to its number. Each weight has the shape shown in the picture, so other weights can be hung on its left and right. Arrange weights on the left and right sides of a large balance scale while satisfying all of the following rules.

  1. For any weight, only lighter weights may be hung on its left side, and only heavier weights may be hung on its right side.
  2. The shapes formed on the left and right sides of the large scale must be mirror images around the center post. If n is odd, exactly one weight is not used.
  3. A weight may be hung at depth d only after every possible position at depth d-1 has already been filled. In other words, the used weights must be placed with minimum possible depth.
  4. When placing new weights at the same depth, the left-side shape is filled from the left position first, and the right-side shape is filled from the right position first.
  5. After all weights are placed, the large balance scale must be balanced. In this problem, it is balanced when the total weight on both sides is the same.

If such an arrangement exists, output the two side shapes.

Input

The first line contains an integer n. (2 ≤ n ≤ 100,000)

Output

On the first line, print the weight numbers in the left-side shape. On the second line, print the weight numbers in the right-side shape. Treat each side shape as a rooted binary tree and print its preorder traversal, separated by spaces.

If no valid arrangement exists, print only -1 on the first line.

Hint