Enumerating Brackets

Given N and M, print the M-th balanced bracket sequence of length N in lexicographic order, where '(' is smaller than ')'.

Medium6CombinatoricsDynamic programmingGreedyImplementationInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

A balanced bracket sequence is a string made only of the characters ( and ) in which every opening bracket has a matching closing bracket, and every closing bracket has a matching opening bracket. For example, (())() is a balanced bracket sequence, while (())(() and ())(() are not.

Let AA and BB be two bracket sequences of the same length. We say that AA is lexicographically smaller than BB, written A<BA < B, when both of the following hold:

  1. AA and BB differ in at least one position.
  2. At the leftmost position where AA and BB differ, AA has a ( and BB has a ).

For example, (())()<()()()(())() < ()()(), because the two strings first differ at the second position from the left, where the first string has a ( and the second has a ).

For a fixed length NN, the relation << orders all balanced bracket sequences of length NN. For N=6N = 6 the order is:

  1. ((()))
  2. (()())
  3. (())()
  4. ()(())
  5. ()()()

Given NN and a positive integer MM, find the MM-th balanced bracket sequence of length NN in this order.

Input

The first line contains an even integer NN (2N20002 \le N \le 2000) and a positive integer MM, separated by a space. MM is at most 101810^{18}, and MM is also at most the number of balanced bracket sequences of length NN.

Output

Print the MM-th balanced bracket sequence of length NN in the order described above.