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 = [({'(':1,')':-1})[c] for c in input()]
v = 0
ans = 0
cnt = 1
fst = []
for i,c in enumerate(s):
  v += c
  if v > 0 or (c==-1 and v>=0):
      if c>0:
          fst.append(i)
      else:
          j = fst.pop()
          #print(s[j:i+1])
          if i-j+1 > ans:
              ans = i-j+1
              cnt = 1
          elif i-j+1 == ans:
              cnt += 1
  else:
      if c>0:
          p0 = i
          v = 1
          fst = [i]
print(ans,cnt)
