Codeforces Round 138 (Div. 2)
C
Bracket Sequence
Codeforces
未评级
原题
← BD →
翻译中…

A bracket sequence is a string, containing only characters "(", ")", "[" and "]".

翻译中…

A correct 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 "()[]", "([])" are correct (the resulting expressions are: "(1)+[1]", "([1+1]+1)"), and "](" and "[" are not. The empty string is a correct bracket sequence by definition.

翻译中…

A substring $*s*[*l*... *r*]$ $(1 ≤ *l* ≤ *r* ≤ |*s*|)$ of string $*s* = *s*_{1}*s*_{2}... *s*_{|*s*|}$ (where $|*s*|$ is the length of string $*s*$) is the string $*s*_{*l*}*s*_{*l* + 1}... *s*_{*r*}$. The empty string is a substring of any string by definition.

翻译中…

You are given a bracket sequence, not necessarily correct. Find its substring which is a correct bracket sequence and contains as many opening square brackets «[» as possible.

翻译中…

Input

翻译中…

The first and the only line contains the bracket sequence as a string, consisting only of characters "(", ")", "[" and "]". It is guaranteed that the string is non-empty and its length doesn't exceed $10^{5}$ characters.

翻译中…

Output

翻译中…

In the first line print a single integer — the number of brackets «[» in the required bracket sequence. In the second line print the optimal sequence. If there are more than one optimal solutions print any of them.

翻译中…

样例

Input #1
([])
Output #1
1
([])
InputCopy OutputCopy
Input #2
(((
Output #2
0
InputCopy OutputCopy
题目信息
题号
224C
时间限制
2 s
内存限制
256 MB

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。