CF BUDDY
← Problems·

1305B · Kuroni and Simple Strings

1200 · constructive algorithms, greedy, strings

Problem: Now that Kuroni has reached 10 years old, he is a big boy and doesn't like arrays of integers as presents anymore. This year he wants a Bracket sequence as a Birthday present. More specifically, he wants a bracket sequence so complex that no matter how hard he tries, he will not be able to remove a simple subsequence!

We say that a string formed by nn characters '(' or ')' is simple if its length nn is even and positive, its first n2\frac{n}{2} characters are '(', and its last n2\frac{n}{2} characters are ')'. For example, the strings () and (()) are simple, while the strings )( and ()() are not simple.

Kuroni will be given a string formed by characters '(' and ')' (the given string is not necessarily simple). An operation consists of choosing a subsequence of the characters of the string that forms a simple string and removing all the characters of this subsequence from the string. Note that this subsequence doesn't have to be continuous. For example, he can apply the operation to the string ')()(()))', to choose a subsequence of bold characters, as it forms a simple string '(())', delete these bold characters from the string and to get '))()'.

Kuroni has to perform the minimum possible number of operations on the string, in such a way that no more operations can be performed on the remaining string. The resulting string does not have to be empty.

Since the given string is too large, Kuroni is unable to figure out how to minimize the number of operations. Can you help him do it instead?

A sequence of characters aa is a subsequence of a string bb if aa can be obtained from bb by deletion of several (possibly, zero or all) characters.

Input Format: The only line of input contains a string ss (1s10001 \le |s| \le 1000) formed by characters '(' and ')', where s|s| is the length of ss.

Output Format: In the first line, print an integer kk  — the minimum number of operations you have to apply. Then, print 2k2k lines describing the operations in the following format:

For each operation, print a line containing an integer mm  — the number of characters in the subsequence you will remove.

Then, print a line containing mm integers 1a1<a2<<am1 \le a_1 < a_2 < \dots < a_m  — the indices of the characters you will remove. All integers must be less than or equal to the length of the current string, and the corresponding subsequence must form a simple string.

If there are multiple valid sequences of operations with the smallest kk, you may print any of them.

Note: In the first sample, the string is '(()(('. The operation described corresponds to deleting the bolded subsequence. The resulting string is '(((', and no more operations can be performed on it. Another valid answer is choosing indices 22 and 33, which results in the same final string.

In the second sample, it is already impossible to perform any operations.

Sample Cases

Case 1

Input

(()((

Output

1
2
1 3

Case 2

Input

)(

Output

0

Case 3

Input

(()())

Output

1
4
1 2 5 6

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