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 math

t = sys.stdin.read().split("\n")
if (len(t) > 1):
    t.pop(-1)
t = t[0]

def splitz(lista, asdf):
    ret = []
    aux = str(lista).replace(" ","").replace("[","").replace("]","").split('-1')
    for i in aux:
        aux2 = []
        for value in i.split(','):
            if value != '':
                aux2.append(int(value))
        if aux2!=[]:
            ret.append(aux2)
    return ret
        
    
        
    
def check_for_matching(string):
    o = []
    index = 0
    #print("=========================")
    #print("String:" + string)
    for char in string:
        index +=1
        if char == "(":
            o.append("(")
        elif char == ")":
            if o!=[]:
                o.pop(-1)
                if(o == []):
                    #print("Submatch!")
                    #print(string[0:index])
                    #print("Length:" + str(len(string[0:index])))
                    return [string[0:index], True]
                    break
            else:
                #print("invalid sub string!")
                #print(string[0:index])
                return [string[0:index], False]

    #print("No substring found")
    return [[],False]

base = t
index = 0
substrings = []

while True:
    aux = check_for_matching(t)
    if (len(t) == 0):
        break
    if aux[1] == False:
        substrings.append(-1)
        index+=1
    elif aux[1] == True:
        substrings.append(len(aux[0]))
        index+=len(aux[0])
    
    t = base[index::]

print(substrings)
if -1 in substrings:
    answers = list(splitz(substrings, -1))
    print(answers)
    #print(answers)
    max_length = 0
    count = 1
    for aux in answers:
        if sum(aux) == max_length:
            count+=1
        elif sum(aux) > max_length:
            max_length = sum(aux)
            count=1
    print("{0} {1}".format(max_length, count)) 
        
else:
    print("{0} 1".format(sum(substrings)) )

#print(str(max_length) + " " + str(count))
        
    



