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

MAX_LEN = 0
COUNT = 0

if __name__ == "__main__":

    _brackets_count = 0
    cur_len = 0

    line = next(sys.stdin)
    for s in line:
        cur_len += 1
        if s == '(':
            _brackets_count += 1
        elif s == ')':
            _brackets_count -= 1

        if _brackets_count == 0:
            if cur_len > MAX_LEN:
                MAX_LEN = cur_len
            COUNT += 1
            cur_len = 0
        elif _brackets_count < 0:
            _brackets_count = 0
            cur_len = 0

    print(f'{MAX_LEN} {COUNT or 1}')
