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
sys.setrecursionlimit(100000)
OPEN, CLOSE = '(', ')'

def mistery(data):
    terminated_counter = 0
    counter = 0
    open_index = 0
    for char in data:
        if char == OPEN:
            terminated_counter += 1
            open_index = counter
        elif char == CLOSE and terminated_counter > 0:
            terminated_counter -= 1
            data[open_index] = 1
            data[counter] = 1
            return mistery(data)

        counter += 1
    return data


def solve(string):
    groups = defaultdict(int)
    group = 0
    for c in [x for x in mistery(list(string.strip())) if x]:
        if c not in [OPEN, CLOSE]:
            group += c
        elif group:
            groups[group] += 1
            group = 0

    if group: groups[group] += 1

    if groups:
        print("%s %s" % (max(groups), groups[max(groups)]))
    else:
        print("0 1")


solve(sys.stdin.readline())







