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>.
#! python3
# longest regular bracket sequence

import re

sequence = input()
sequence = re.sub(r'\(\)', '2 ', sequence)

bracket_regex = re.compile(r'(\((\d+\s)+\))')

while bracket_regex.findall(sequence):
    patterns = bracket_regex.findall(sequence)
    for ptn in patterns:
        num = sum([int(p) for p in ptn[0][1:-2].split(' ')]) + 2
        sequence = sequence.replace(ptn[0], str(num) + ' ')

num_regex = re.compile(r'((\d+\s)+)')
patterns = num_regex.findall(sequence)
for ptn in patterns:
    num = sum([int(p) for p in ptn[0][:-1].split(' ')])
    sequence = sequence.replace(ptn[0], str(num)+' ')

one_num_regex = re.compile(r'(\d+\s)')
char_nums = [ int(p[:-1]) for p in one_num_regex.findall(sequence)]
if char_nums:
    max_length = max(char_nums)
    max_length_num = char_nums.count(max_length)
    print(max_length, max_length_num)
else:
    print(0, 1)

# class Stack():
#     def __init__(self, stack = None):
#         if type(stack) is type([]):
#             self.stack = stack
#         elif stack is None:
#             self.stack = []
#         else:
#             print('\nError Message:\n\tYour input is not type of list!\n\tPlease enter list type!\n')
#
#     def get_length(self):
#         return len(self.stack)
#
#     def push(self, e):
#         self.stack.append(e)
#         return self.stack
#
#     def pop(self):
#         try:
#             sEl = self.stack.pop()
#             return (sEl, self.stack)
#         except IndexError:
#             print('\nError Message:\n\tThere is no element in the stack!\n')
#
#     def clear(self):
#         self.stack = []
#
# sequence = input()
# if list(sequence.rstrip('(')).count('(') > list(sequence.lstrip(')')).count(')'):
#     sequence = sequence[::-1]
#
# max_length = 0
# max_length_num = 0
#
# def max_length_update(current_length):
#     global max_length, max_length_num
#     if current_length == max_length:
#         max_length_num += 1
#     elif current_length > max_length:
#         max_length = current_length
#         max_length_num = 1
#
# bracket_stack = Stack()
# current_length = 0
# sequent_flag_index = -1
# for i in range(len(sequence)):
#     if sequence[i] == '(':
#         if bracket_stack.get_length() == 0 and sequent_flag_index != i-1:
#             max_length_update(current_length)
#             bracket_stack.push(i)
#             current_length = 0
#         else:
#             bracket_stack.push(i)
#     elif sequence[i] == ')':
#         if bracket_stack.get_length() != 0:
#             bracket_stack.pop()
#             current_length += 2
#             if bracket_stack.get_length() == 0:
#                 sequent_flag_index = i
#     if i == len(sequence)-1:
#         max_length_update(current_length)
#
# if max_length == 0:
#     print(0, 1)
# else:
#     print(max_length, max_length_num)
