# Arup Guha
# 8/18/2021
# Solution to 2021 UCF Locals Qualifying Problem: Don't Complicate It!

# Get input string, set up height stack.
s = input("").strip()
res = 0
height = []

# Go through each char.
for i in range(len(s)):

    # Add this to the stack, the current height is 0.
    if s[i] == '(':
        height.append(0)

    # Processing the match with the top open.
    elif s[i] == ')':

        # The total complexity is 1 plus the nested complexity.
        curH = height.pop()
        res += (curH+1)

        # Here we update the parens right below us, if necessary.
        if len(height) > 0:
            tmp = height.pop()
            height.append(max(tmp, curH+1))

# Ta da
print(res)
