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>.
s,l,num,flag,flag1=input(),0,1,0,0
lef,rig=0,0
d,length,length1,m=[],0,0,0
i=0
while i<len(s):
    if not flag:#不处于配对状态
       if s[i] == '(':#进入配对
         lef+=1
         flag=1
    else:#当前处于配对状态
        if s[i]=="(":
            lef+=1
        else:
            rig+=1
        if rig==lef and not flag1:#not flag1意味着没有上一组数据需要判定
            flag=0#退出配对状态
            length1,m=lef*2,i#暂存当前完美配对的结束长度和位置
            lef,rig=0,0
            flag1=1
        if rig==lef and flag1:#有上一组数据
            if i-2*lef==m: #可拼贴
              length1+=lef*2
              m=i
              lef,rig=0,0
              flag=0
            else:#不可以与上一次的拼贴
                d.append(length1)#上一次数据存入
                length1,m=lef*2,i
                lef,rig=0,0
    i+=1
if length1:
    d.append(length1)
else:
    d.append(min(lef,rig)*2)
for j in d:#输出答案
    if j>l:
        l=j
        num=1
    elif j==l and j!=0:
        num+=1
print(l,num)

