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()
open,close = '(<{[',')}>]'
def findlongest(S,rev):
    freqq = [0]*100001
    r1 = 4 if rev==True else 0
    r2 = r1//2
    if rev :
        S=S[::-1]
    stt = []
    longest,long = 0,0
    # number,hh = 0,0
    for i in S:
        # hh +=1

        if len(stt)!=0 and (ord(stt[-1]) == (ord(i)-2+r1) or ord(stt[-1]) == (ord(i)-1+r2)) :
            stt.pop()
            long+=2
            # number+=1 if( hh==len(S)) else 0

        elif i in (close if rev else open):
            stt.append(i)
            # number+=1 if( hh==len(S)) else 0

        else:
            longest = max(longest,long)
            freqq[longest]+=1 if longest else 0
            long = 0
            stt.append(i)

    longest = max(longest,long)
    freqq[longest]+=1 if longest else 0

    # number=1 if longest == 0 else number
    return longest,freqq[longest]

L= [*findlongest(S,False),*findlongest(S,True)]
if L[0]==0 and L[2]==0:
    print('0 1')

elif L[0]==L[2] and L[1]==L[3]:
    print(L[0],L[1])
else:
    if L[0]<L[2]:
        print(L[0],L[1])
    elif L[0]>L[2]:
        print(L[2],L[3])
    else:
        print(L[0],min(L[1],L[3]))


