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
        if (!s.matches("[()]+")) {
            System.out.println("Invalid input");
            return;
        }

        Stack<Integer> stack = new Stack<>();
        stack.push(0); // base score

        for (char c : s.toCharArray()) {
            if (c == '(') {
                stack.push(0);
            } else {
                int v = stack.pop();
                int w = stack.pop();
                stack.push(w + Math.max(2 * v, 1));
            }
        }

        System.out.println(stack.pop());
    }
}