This page is still under construction.

Parts of this page are still being built. What you see may change.

Brackets

Time limit1sMemory limit128 MB

Summary
Given n and k, print the k-th correct bracket sequence of length 2n in lexicographic order.
Level

Medium6 of 10

Topics
Combinatorics, Dynamic programming, Greedy
Solved
No attempts yet

Problem

A correct bracketing is a string of the brackets ( and ) in which the number of opening brackets equals the number of closing brackets, and every prefix contains at least as many opening brackets as closing brackets. For example, ()() is a correct bracketing, while ())( is not, because its prefix ()) has more closing brackets than opening brackets.

Given two correct bracketings of length 2n2n, the earlier one is the bracketing that has an opening bracket at the first position where the two strings differ. This ordering is exactly lexicographical order when ( is treated as smaller than ).

Write a program that reads two integers nn and kk, then finds and prints the lexicographically kk-th correct bracketing of length 2n2n (bracketings are numbered starting from 11).

Input

A single line with two integers nn and kk (1≤n≤40001 \le n \le 4000, 1≤k≤10181 \le k \le 10^{18}), separated by one space.

Output

Print the correct bracketing of length 2n2n that ranks kk-th among all correct bracketings of length 2n2n in lexicographical order. The input is guaranteed to be chosen so that this bracketing always exists.

Examples1

  1. Example 1

    Input
    3 2
    
    Expected output
    (()())