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 
# # For getting input from input.txt file 
# sys.stdin = open('inputf.in', 'r')  
# # Printing the Output to output.txt file 
# sys.stdout = open('outputf.in', 'w') 

# started at 16:27

W,st = list(input()),[]
d = {}
curr_max,all_max,cnt = 0,0,0
for i in W:
	if i == '(':
		# curr_max = 0
		# all_max = max(curr_max,all_max)
		if curr_max>=all_max:
				all_max = curr_max
				d[all_max] = 1 if all_max not in d else d[all_max]+1
		st.append('(')
	elif i==')':
		if len(st) and st[-1]=='(':
			curr_max += 2
			# all_max = max(curr_max,all_max)
			# print("i",curr_max,all_max)
			if curr_max>=all_max:
				# print("jj",curr_max,all_max,d)
				all_max = curr_max
				d[all_max] = 1 if all_max not in d else d[all_max]+1
			st.pop()
		else:
			curr_max = 0

print(all_max,d[all_max])
# submitted 22:28
