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 longestValidParentheses(s):
    if len(s) < 2:
        return 0
    tans = 0
    st = []
    cans = 0
    mn = float("inf")
    dp = [0] * len(s)
    for ind, i in enumerate(s):
        if i == "(":
            st.append(ind)
        if i == ")":
            if st:
                id = st.pop()
                if id - 1 >= 0 and ind - 1 >= 0:
                    dp[ind] = dp[id - 1] + dp[ind - 1] + 2
                elif id - 1 < 0:
                    dp[ind] = dp[ind - 1] + 2
    mx=max(dp)
    if mx==0:
        print(0,1)
    else:
        print(mx,dp.count(mx))

longestValidParentheses(input())
