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>.
# coding = utf-8
"""
    https://codeforces.com/contest/5/problem/C
"""
from collections import deque
import fileinput

def peek(stack):
    if len(stack) > 0:
        return stack[0]
    else:
        return (-1, "")

def longest(string):
    stack = deque()
    
    top_index = -1
    top_char  = ""
    current_max = 0
    current_count = 0
    for current_index, c in enumerate(string):
        if c != top_char and top_index != -1 and c == ')':
            try:
                stack.popleft()
            except:
                pass
            top_index, top_char = peek(stack)
            current_length = current_index - top_index
            if current_length > current_max:
                current_max = current_length
                current_count = 1
            elif current_length == current_max:
                current_count = current_count + 1

        else:
            stack.appendleft((current_index, c))
            top_index, top_char = current_index, c
    if current_max == 0:
        return 0, 1
    return current_max, current_count

if __name__ == '__main__':
    f = fileinput.input()
    string = f.readline().strip()
    print(longest(string))
