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
import time

from collections import defaultdict, Counter

OPEN, CLOSE = '(', ')'

def magic(data):
    open_index, open_num, step= 0, 0, 0
    chars_count = len(data)
    avoid = set()
    while step <= chars_count - 1:
        if step in avoid:
            step += 1
            continue
        char = data[step]
        if char == OPEN:
            open_num += 1
            open_index = step
        elif char == CLOSE and open_num > 0:
            open_num -= 1
            data[open_index] = 1
            data[step] = 1
            avoid.add(step)
            avoid.add(open_index)
            step, open_index, open_num = 0, 0, 0
            continue
        step += 1
    return data


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

    if group: groups[group] += 1

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

print(solve(sys.stdin.readline()))


