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

exp = list(sys.stdin.readline().strip())

stack = []


while len(exp) > 0:
	if len(stack) > 1 and len(stack[-1]) > 1 and len(stack[-2]) > 1:
		while len(stack) > 1 and len(stack[-1]) > 1 and len(stack[-2]) > 1:
			x2 = stack.pop()
			x1 = stack.pop()
			stack.append(x1 + x2)

	else:
		symbol = exp.pop(0)

		if symbol == ')' and len(stack) > 0 and stack[-1] == '(':
			stack.pop()
			stack.append('()')
		elif len(stack) > 1 and stack[-2] == '(' and len(stack[-1]) > 1 and symbol == ')':
			center = stack.pop()
			left = stack.pop()	
			stack.append('({})'.format(center))
		else:
			stack.append(symbol)

if len(stack) > 1 and len(stack[-1]) > 1 and len(stack[-2]) > 1:
	while len(stack) > 1 and len(stack[-1]) > 1 and len(stack[-2]) > 1:
		x2 = stack.pop()
		x1 = stack.pop()
		stack.append(x1 + x2)


longest = 0
num_longest = 0

while len(stack) > 0:
	x = stack.pop()
	if len(x) > 1:
		if len(x) == longest:
			num_longest += 1
		elif len(x) > longest:
			longest = len(x)
			num_longest = 1

if num_longest == 0:
	print('0 1')
else:
	print('{} {}'.format(longest, num_longest))
