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>.
from collections import defaultdict

s = list(input())
cnt = 0
g = defaultdict(int)
last = 0
for i, ch in enumerate(s):
    if ch == '(':
        cnt += 1
    else:
        cnt -= 1
    if cnt < 0:
        cnt = 0
        last = i
    elif cnt == 0:
        g[i - last] += 1
ans_k, ans_v = -1, -1
for k, v in g.items():
    if k > ans_k:
        ans_k = k
        ans_v = v
g.clear()
cnt, last = 0, len(s)
for i in range(len(s) - 1, -1, -1):
    if s[i] == ')':
        cnt += 1
    else:
        cnt -= 1
    if cnt < 0:
        cnt = 0
        last = i
    elif cnt == 0:
        g[last - i] += 1
for k, v in g.items():
    if k > ans_k:
        ans_k = k
        ans_v = v
if ans_k == -1:
    print(0, 1)
else:
    print(ans_k, ans_v)