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 math
import itertools
import random
import sys
from heapq import *
# sys.setrecursionlimit(999999999) # Will MLE PyPy but not Python
def input():return sys.stdin.readline().strip()
debug=1
# Leeisateam

s=input()
best=0
count=1
last=[-1]
for i in range(len(s)):
    if s[i]=="(":
        last.append(i-1)
    else:
        if len(last)>1:
            if i-last[-1] > best:
                best=i-last[-1]
                count=1
            elif i-last[-1] == best:
                count += 1
        last.pop()
        if len(last)==0:
            last=[i-1]
    #print("i",i,"best",best,"last",last)
print(best, count)








