Under construction

Still being built. Things may change

Bad Tree

Time limit1sMemory limit1024 MB

Summary
Find the kth lexicographically smallest permutation of 1 to n that, inserted into a BST in order, produces a tree of height n-1.
Level

Medium6 of 10

Topics
Combinatorics, Dynamic programming, Tree
Solved
No attempts yet

Problem

Binary search trees speed up searches only when the height of the tree is much smaller than the number of values stored in it. Judges, however, try to build worst case data. So in binary search tree problems, the judges almost always create data where nn nodes are inserted in a particular order that makes the tree height the worst possible, n−1n-1.

Without loss of generality, let the nn values to insert be 1, 2, 3, ..., n. For n=5n=5, inserting the values in the order 5, 1, 4, 3, 2 gives a binary search tree of height 4.

Many permutations of the integers 1 through nn produce a tree of height n−1n-1 when inserted in that order. Write a program that finds the kkth permutation in lexicographical order among them.

Input

The input is a single line with two space-separated integers nn (1≤n≤1001 \le n \le 100) and kk (1≤k≤10181 \le k \le 10^{18}). nn is the number of nodes, and kk is the position of the wanted permutation in lexicographical order.

Output

Print the kkth permutation of the integers 1 through nn that, when inserted into a binary search tree in that order, produces a tree of height n−1n-1. Print the numbers on one line, with a space after each number. If no such permutation exists, print -1.

Examples4

  1. Example 1

    Input
    5 12
    
    Expected output
    5 1 4 3 2
    
  2. Example 2

    Input
    4 2
    
    Expected output
    1 2 4 3
    
  3. Example 3

    Input
    6 1
    
    Expected output
    1 2 3 4 5 6
    
  4. Example 4

    Input
    3 50
    
    Expected output
    -1