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>.
def magic(value=None):
    pairs = {}
    maximum, count = 0, 0
    num_of_opened, indices_of_opened = 0, []
    for i, char in enumerate(value or input()):
        if char == '(':
            indices_of_opened.append(i)
        elif indices_of_opened:
            o = indices_of_opened.pop()
            if o - 1 in pairs:
                start_of_previous = pairs[o - 1][0]
                pairs[i] = (start_of_previous, i)
                item_size = i - start_of_previous + 1
            else:
                item_size = i - o + 1
                pairs[i] = (o, i)
            if item_size > maximum:
                maximum = item_size
                count = 1
            elif item_size == maximum:
                count += 1
    if not maximum:
        return "0 1"
    return "%s %s" % (maximum, count)


# assert magic(")((())))(()())") == "6 2"
# assert magic("))(") == "0 1"
# assert magic("()(())()") == "8 1"
# assert magic("((((()(((") == "2 1"
# assert magic("))))()())))") == "4 1"
# assert magic("(()())()(())()()())())()((()(()(())()()())((()(())()(()()()()))()(())()(((()())()(()((())()(())(()))") == "28 1"
# assert magic(")(()(((((())))))(((()))))))((()(((((((())())()))))((((((((())))((((((())))))(()((((()))))(()))))))))") == "68 1"

print(magic())