思路:模拟题。直接用一个cnt变量,表示模拟栈括号匹配时的深度,然后每次成功匹配一个')'时,更新答案,最终输出结果即可

代码:

import sys
input = lambda: sys.stdin.readline().strip()

import math
inf = 10 ** 18

def I():
    return input()

def II():
    return int(input())

def MII():
    return map(int, input().split())

def GMI():
    return map(lambda x: int(x) - 1, input().split())

def LI():
    return input().split()

def LII():
    return list(map(int, input().split()))

def LFI():
    return list(map(float, input().split()))

fmax = lambda x, y: x if x > y else y
fmin = lambda x, y: x if x < y else y
isqrt = lambda x: int(math.sqrt(x))

'''

'''

def solve():
    s = I()

    ans = cnt = 0
    for c in s:
        if c == '(':
            cnt += 1
        else:
            ans = fmax(ans, cnt)
            cnt -= 1

    print(ans)

t = 1
# t = II()
for _ in range(t):
    solve()