This is yet another problem dealing with regular bracket sequences.

We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical expression. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not. 

You are given a string of «(» and «)» characters. You are to find its longest substring that is a regular bracket sequence. You are to find the number of such substrings as well.
The first line of the input file contains a non-empty string, consisting of «(» and «)» characters. Its length does not exceed 10<sup class="upper-index">6</sup>.
import sys

from collections import defaultdict

OPEN, CLOSE = '(', ')'

def magic(data):
    open_index, open_num, step= 0, 0, 0
    chars_count = len(data)
    indices = []
    while step <= chars_count - 1:
        char = data[step]
        if char == OPEN:
            open_num += 1
            open_index = step
            indices.append(open_index)

        elif char == CLOSE and open_num > 0:
            open_num -= 1
            data[open_index] = 1
            data[step] = 1
            step = 0
            open_index, open_num = 0, 0
            continue
        step += 1
    return data



def solve(string):
    group = 0
    chars = list(string.strip())
    brackets = [OPEN, CLOSE]
    maxgroup = 0
    maxgroupcount = 0
    for c in magic(chars):
        if c not in brackets:  group += c
        elif group:
            if group == maxgroup:
                maxgroupcount += 1
            elif maxgroup < group or maxgroup == 0:
                maxgroupcount = 1
                maxgroup = group
            group = 0
    if group:
        if group == maxgroup:
            maxgroupcount += 1
        elif maxgroup < group or maxgroup == 0:
            maxgroupcount = 1
            maxgroup = group

    print(maxgroup, maxgroupcount)

    if maxgroup:
        return "%s %s" % (maxgroup, maxgroupcount)
    else:
        return "0 1"


solve(sys.stdin.readline())







