import java.util.Scanner;
import java.util.Stack;

public class ParenthesesScore {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();

        // Check for invalid characters
        for (char c : s.toCharArray()) {
            if (c != '(' && c != ')') {
                System.out.println("Invalid input");
                return;
            }
        }

        // Stack-based approach
        Stack<Integer> stack = new Stack<>();
        stack.push(0); // Base score

        for (char c : s.toCharArray()) {
            if (c == '(') {
                stack.push(0); // Start a new frame
            } else {
                int v = stack.pop();
                int top = stack.pop();
                // If "()", score = 1; else double nested
                stack.push(top + Math.max(2 * v, 1));
            }
        }

        System.out.println(stack.pop());
    }
}