#include <stdio.h>


double res;
int n, i, u, cnt;
int main(void) {
	freopen("brackets.in", "r", stdin);
	freopen("brackets.out", "w", stdout);
	res = 0;
	n = 0;
	i = 0, u = 0, cnt = 0;
	for (; ; i++) {
		int c = getc(stdin);
		if (c != '(' && c != ')') break;
		n++;
		((c == '(')? u++ : u--);
		if (u > 0) {
			cnt++;
			res += cnt;
		} else {
			cnt = 0;
		}
	}
	res += (n + 1.0) * (n + 2) / 2.0;
	printf("%0.0lf\n", res);
	return 0;
}
