cho.sh
Notes
Loading...

Magic Orbs

Time limit

2s

Memory limit

128 MB

Problem

A wizard wants to collect as many treasures as possible from a line of N = 2^m rooms. The rooms are numbered from 1 to N, and each room contains one treasure. There are no doors between rooms, so the only way to enter or move between rooms is by using magic orbs.

The wizard has exactly one IN orb, one OUT orb, and one orb A_k for each 1 <= k <= N-1.

  • IN must be used first. It places the wizard in one room. The wizard cannot know that room in advance, but after entering, the room number M is known.
  • A_k moves the wizard exactly k rooms left or exactly k rooms right. The wizard chooses the direction, but the destination must still be between rooms 1 and N.
  • Each orb can be used at most once.
  • OUT must be used last to leave the castle.

Given N and the initial room M, print a visiting order that lets the wizard collect the maximum possible number of treasures. For the given constraints, it is possible to visit every room exactly once.

Input

The first line contains the integer N (2^1 <= N <= 2^13 = 8192). N is a power of two.

The second line contains the integer M (1 <= M <= N), the room entered by using IN.

Output

Starting with M, print N room numbers in visiting order on one line. Put one space between adjacent room numbers.

For consecutive printed rooms, the absolute differences must be exactly the numbers 1, 2, ..., N-1 in some order. If there is more than one valid answer, print any one of them.