CF BUDDY
← Problems·

1023C · Bracket Subsequence

1200 · greedy

Problem: A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()" and "(())" are regular (the resulting expressions are: "(1)+(1)" and "((1+1)+1)"), and ")(", "(" and ")" are not.

Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.

You are given a regular bracket sequence ss and an integer number kk. Your task is to find a regular bracket sequence of length exactly kk such that it is also a subsequence of ss.

It is guaranteed that such sequence always exists.

Input Format: The first line contains two integers nn and kk (2kn21052 \le k \le n \le 2 \cdot 10^5, both nn and kk are even) — the length of ss and the length of the sequence you are asked to find.

The second line is a string ss — regular bracket sequence of length nn.

Output Format: Print a single string — a regular bracket sequence of length exactly kk such that it is also a subsequence of ss.

It is guaranteed that such sequence always exists.

Sample Cases

Case 1

Input

6 4
()(())

Output

()()

Case 2

Input

8 8
(()(()))

Output

(()(()))

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback