Under construction

Still being built. Things may change

K-th good string

Time limit2sMemory limit512 MB

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

Hard8 of 10

Topics
Dynamic programming, String, Combinatorics
Solved
No attempts yet

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 (1≤K≤1091 \le K \le 10^9).

Output

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

Examples5

  1. Example 1

    Input
    ()))((()())
    3
    
    Expected output
    (())
    
  2. Example 2

    Input
    ))))))))))))((((((((((
    1
    
    Expected output
    -1
    
  3. Example 3

    Input
    (())(()(()))
    1
    
    Expected output
    (((())))
    
  4. Example 4

    Input
    (())))()((())())
    8
    
    Expected output
    ()
    
  5. Example 5

    Input
    (
    1000000000
    
    Expected output
    -1