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=input().strip()

X=[0]

for s in S:
    if s=="(":
        X.append(X[-1]+1)
    else:
        X.append(X[-1]-1)

#print(X)

MAX=max(X)
MIN=min(X)

A=[[] for i in range(MAX-MIN+2)]

for i in range(len(X)):
    A[X[i]-MIN].append(i)

ANS=0
ANSIND=1

for j in range(MAX-MIN+2):

    for i in range(len(A[j])):
        a=A[j][i]
        if a+1<len(X) and i+1<len(A[j]) and X[a]==X[a+1]-1:
            ans=A[j][i+1]-A[j][i]

            if ANS==ans:
                ANSIND+=1
            elif ANS<ans:
                ANS=ans
                ANSIND=1

print(ANS,ANSIND)
