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>.
from queue import LifoQueue
test = 1
#test = input()
while test:
    s = input()
    n = len(s)
    stack1 = LifoQueue(n+1)
    for i in range(n):
        if s[i] == '(':
            stack1.put('(')
        else:
            if stack1.empty():
                stack1.put(')')
            else:
                x = stack1.get()
       #         print("x ", x, end=' ')
                if not stack1.empty():
                    y = stack1.get()
        #            print("y ", y, end=' ')
               #     print(x, y)
                    if x == ')':
           #             stack1.put(y)
                        stack1.put(x)
                    elif x != ')' and y == ')':
                        stack1.put(y)
                        if x == '(':
                            stack1.put(1)
                        else:
                            stack1.put(x)
                            stack1.put(')')
                    elif x == '(' and y == '(':
                       # print('*')
                        stack1.put('(')
                        stack1.put(1)
                    elif x != '(' and y != '(':

                        g = x + y
                        if not stack1.empty():
                            z = stack1.get()
         #                   print(z)
                            if z == '(':
                                z = 1
                                g += z
                            elif z == ')':
                                stack1.put(z)
                            else:
                                g += z
           #             else:
          #                  print("no z")
                        stack1.put(g)
                    else:
                        if x == '(':
                            x = 1
                        if y == '(':
                            y = 1
                        g = x + y
                        if not stack1.empty():
                            z = stack1.get()
            #                print(z)
                            if z == '(':
                                stack1.put(z)
                            elif z == ')':
                                stack1.put(z)
                            else:
                                g += z
             #           else:
              #              print("no z")
        #                print(g)
                        stack1.put(g)
                else:
               #     print("no y")
                    if x == '(':
                        stack1.put(1)
                    else:
                        stack1.put(x)
                        stack1.put(')')
                #print()
    ans = 0
    lis = list()
    while not stack1.empty():
        x = stack1.get()
        if not(x == ')' or x == '('):
            ans = max(x, ans)
            lis.append(x)
    cnt = 0
    for x in lis:
        cnt += x == ans
    if ans:
        print(ans*2, cnt)
    else:
        print("0 1")
    test -= 1