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*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>... *s*<sub class="lower-index">|*s*|</sub> (where |*s*| is the length of string *s*) is the string *s*<sub class="lower-index">*l*</sub>*s*<sub class="lower-index">*l* + 1</sub>... *s*<sub class="lower-index">*r*</sub>. 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.
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<sup class="upper-index">5</sup> characters.
def longest_correct_bracketing_substring(s):
    stack = []
    max_len = 0
    last_invalid = -1
    start = 0
    end = 0
    for i, c in enumerate(s):
        if c == '(' or c == '[':
            stack.append(i)
        elif c == ')' or c == ']':
            if not stack:
                last_invalid = i
            elif (c == ')' and s[stack[-1]] != '(') or (c == ']' and s[stack[-1]] != '['):
                last_invalid = i
            else:
                stack.pop()
                if not stack:
                    if max_len < i - last_invalid:
                        max_len = i - last_invalid
                        start, end = last_invalid + 1, i
                else:
                    if max_len < i - stack[-1]:
                        max_len = i - stack[-1]
                        start, end = stack[-1] + 1, i
    return s[start:end+1]

s = input()
stack = []
ans = []
#idea is to do a stack, and if you encounter a close that is not matching, end the search
#restart if possible
#for each search, remember the bracketing
curr = []
for x in s:
    if len(stack) == 0:
        stack.append(x)
        curr.append(x)
    else:
        if x == "(" or x == "[":
            stack.append(x)
            curr.append(x)
        elif x == ")" and stack[-1] == "(":
            stack.pop()
            curr.append(")")
        elif x == "]" and stack[-1] == "[":
            stack.pop()
            curr.append("]")
        else:
            ans.append(curr)
            stack = []
            curr = []
ans.append(curr)
final_str = ""
final_cnt = 0
correct = []
for x in ans:
    temp = longest_correct_bracketing_substring(x)
    correct.append(temp)
for x in correct:
    c = 0
    b = ""
    for y in x:
        b += y
        if y == "]":
            c += 1
    if c >= final_cnt:
        final_cnt = c
        final_str = b
print(final_cnt)
if final_cnt != 0:
    print(final_str)
else:
    print("")