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
import sys, threading
from heapq import heapify, heappop, heappush
from math import log10, floor, pow, gcd, sqrt, inf, log2
from collections import defaultdict, deque, Counter
input = sys.stdin.readline
 
 
############ ---- Input Functions ---- ############
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))
 
def main():
    st = insr()
    n = len(st)
    stack = []
    dp = [0] * n
    length, cnt = 0, 0

    for i in range(n):
        if st[i] == '(':
            stack.append(i)
        elif stack:
            j = stack.pop()
            dp[i] = i - j + 1 + dp[j - 1] if j > 0 else i + 1

            if dp[i] > length:
                length = dp[i]
                cnt = 1
            elif dp[i] == length:
                cnt += 1

    if length == 0:
        print("0 1")
    else:
        print(length, cnt)
   
        
             
        
    
 
threading.stack_size(1 << 27)
sys.setrecursionlimit(1 << 30)
main_thread = threading.Thread(target=main)
main_thread.start()
main_thread.join()




