import sys
input = sys.stdin.readline
x = input().rstrip()
now = 0
ans = 0
for i in range(len(x)-1):
s = x[i:i+2]
if s == "()": # leaf 노드의 깊이를 ans에 더함
ans += now
elif s == "((": # 깊이가 깊어짐
now += 1
elif s == "))": # 깊이가 얕아짐
now -= 1
print(ans)
주석 설명