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>.
def CF_5C():
    sequence=input()
    sequence=sequence.lstrip(')')
    sequence=sequence.rstrip('(')
    result=[]
    for i in range(len(sequence)):
        if sequence[i]=='(':
            for j in range(len(result)):
                if result[j][0]==-1:
                    continue
                else:
                    result[j][0]+=1
                    result[j][1]+=1
            result.append([1,1])
        else:
            for j in range(len(result)):
                if result[j][0]==-1:
                    continue
                elif result[j][0]==0:
                    result[j][0]=-1
                else:
                    result[j][0]-=1
                    result[j][1]+=1
            result.append([-1,0])
        #print(result)
    length=0
    number=0
    for i in range(len(result)):
        if result[i][0]!=0 and result[i][0]!=-1:
            continue
        if result[i][1]>length:
            length=result[i][1]
            number=1
        elif result[i][1]==length:
            number+=1
        else:
            continue
    if length==0:
        print(0,1)
    else:
        print(length,number)
        
    return

CF_5C()