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>.
from sys import stdin

lines, line_index = stdin.readlines(), -1


def get_line():
  global lines, line_index

  line_index += 1
  return lines[line_index]

def main():
  data = get_line().strip()

  max_c = -1
  stack = [-1]
  counter = 0

  for i, c in enumerate(data):
    if c == '(':
      stack.append(i)
    else:
      stack.pop()

      if stack:
        temp_max = max(max_c, i - stack[-1])
        if i - stack[-1] == max_c:
          counter += 1
        elif temp_max > max_c:
          counter = 1
          max_c = temp_max
      else:
        stack.append(i)

  if max_c != -1:
    print('%s %s' % (max_c, counter))
  else:
    print('%s %s' % (0, 1))

main()