K-th good string

Given a bracket string S, list the distinct good strings that appear as subsequences in lexicographic order and print the K-th one.

Hard8Dynamic programmingStringCombinatoricsNo attempts yetTime limit2sMemory limit512 MB

Problem

Good strings are defined as follows.

  • The string () is a good string.
  • If SS is a good string, then (SS...S) is also a good string. In other words, if you write one good string one or more times in a row and wrap the whole result in parentheses, you get a good string.
  • No other string is a good string.

A subsequence of a string XX is a string obtained by deleting zero or more characters from XX.

You are given a string SS. Each character of SS is ( or ).

Let GG be the set of distinct good strings that are subsequences of SS. Because GG is a set, a good string that occurs as a subsequence several times is contained in GG only once. For example, if SS = (()()), then GG contains (), (()), and (()()).

Given KK, write a program that finds the KK-th string of GG in lexicographic order. Indexing starts at 1. In lexicographic comparison, ( comes before ).

Input

The first line contains the string SS. The length of SS is between 1 and 150, inclusive.

The second line contains the integer KK (1K1091 \le K \le 10^9).

Output

Print the KK-th string of GG in lexicographic order. If no such string exists, print -1.