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
from collections import deque

# Reading input faster in Python
input = sys.stdin.readline

# Function for reading integer inputs
def si():
    return int(input())

# Function for reading two integers
def sii():
    return map(int, input().split())

# Function for reading three integers
def siii():
    return map(int, input().split())


# Main function
def main():
    s = input().strip()
    n = len(s)

    d = [-1] * n
    st = deque()

    maxi, cnt = 0, 1

    for i in range(n):
        if not st or s[i] == '(':
            st.append(i)
            continue

        pos = st.pop()

        if s[pos] == '(':
            if d[pos-1] != -1:
                d[i] = d[pos-1]
            else:
                d[i] = pos

            length = i - d[i] + 1
            if length == maxi:
                cnt += 1
            elif length > maxi:
                maxi = length
                cnt = 1

    print(maxi, cnt)

if __name__ == "__main__":
    main()


 	 		 	 		 		   				    		 	