alist = list(input())
stack = []
past = ''
answer = 0
for a in alist:
    if not stack and a == '(':
        stack.append(a)
        past = a
            
    elif past == '(' and a == ')':
        #print("레이저")
        stack.pop()
        past = a
        answer += len(stack)
    
    elif a=='(':
        stack.append(a)
        past = a

    elif past == ')' and a ==')':
        stack.pop()
        answer += 1
        past = ')'

    #print(stack)
print(answer)
        
        





93ba5384c2d17adb1e074d494c06c93021f07e15
<mask token>

<mask token>
for a in alist:
    if not stack and a == '(':
        stack.append(a)
        past = a
    elif past == '(' and a == ')':
        stack.pop()
        past = a
        answer += len(stack)
    elif a == '(':
        stack.append(a)
        past = a
    elif past == ')' and a == ')':
        stack.pop()
        answer += 1
        past = ')'
print(answer)

alist = list(input())
stack = []
past = ''
answer = 0
for a in alist:
    if not stack and a == '(':
        stack.append(a)
        past = a
    elif past == '(' and a == ')':
        stack.pop()
        past = a
        answer += len(stack)
    elif a == '(':
        stack.append(a)
        past = a
    elif past == ')' and a == ')':
        stack.pop()
        answer += 1
        past = ')'
print(answer)

alist = list(input())
stack = []
past = ''
answer = 0
for a in alist:
    if not stack and a == '(':
        stack.append(a)
        past = a
            
    elif past == '(' and a == ')':
        #print("레이저")
        stack.pop()
        past = a
        answer += len(stack)
    
    elif a=='(':
        stack.append(a)
        past = a

    elif past == ')' and a ==')':
        stack.pop()
        answer += 1
        past = ')'

    #print(stack)
print(answer)
        
        




