using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace C_TheMonster
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine();

            int result = 0;
            for(int l = 0; l < line.Length; ++l)
            {
                int left = 0;
                int questionLeft = 0;
                int right = 0;
                int question = 0;

                for (int r = l; r < line.Length; ++r)
                {
                    if (line[r] == '(')
                    {
                        left++;
                        questionLeft++;
                    }
                    else if (line[r] == '?')
                    {
                        questionLeft = Math.Max(questionLeft - 1, 0);
                        question++;
                    }
                    else
                    {
                        // Had (, now have matching )
                        if (left > 0)
                        {
                            questionLeft = Math.Max(questionLeft - 1, 0);
                            left--;
                        }
                        else if (question > 0)
                        {
                            // Had ?, now have matching )
                            question--;
                        }
                        else
                        {
                            break;
                        }
                    }

                    if (left == 0 && right == 0 && question % 2 == 0)
                    {
                        //Console.WriteLine($"{l} {r}");
                        result++;
                    } else if (right == 0 && questionLeft == 0 && question >= left && (question - left) % 2 == 0)
                    {
                        //Console.WriteLine($"{l} {r}");
                        result++;
                    }
                }
            }

            Console.WriteLine(result);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace C_TheMonster
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine();

            int result = 0;
            for(int l = 0; l < line.Length; ++l)
            {
                int left = 0;
                int right = 0;
                int question = 0;

                for(int r = l; r < line.Length; ++r)
                {
                    if(line[r] == '(')
                    {
                        left++;
                    }
                    else if(line[r] == '?')
                    {
                        question++;
                    }
                    else
                    {
                        // Had (, now have matching )
                        if(left > 0)
                        {
                            left--;
                        }
                        else if(question > 0)
                        {
                            // Had ?, now have matching )
                            question--;
                        }
                        else
                        {
                            break;
                        }
                    }

                    if(left == 0 && right == 00 && question % 2 == 0)
                    {
                        result++;
                    }
                }
            }

            Console.WriteLine(result);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace C_TheMonster
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine();

            int result = 0;
            for(int l = 0; l < line.Length; ++l)
            {
                int left = 0;
                int questionLeft = 0;
                int right = 0;
                int question = 0;

                for (int r = l; r < line.Length; ++r)
                {
                    if (line[r] == '(')
                    {
                        left++;
                        questionLeft++;
                    }
                    else if (line[r] == '?')
                    {
                        questionLeft = Math.Max(questionLeft - 1, 0);
                        question++;
                    }
                    else
                    {
                        // Had (, now have matching )
                        if (left > 0)
                        {
                            left--;
                        }
                        else if (question > 0)
                        {
                            // Had ?, now have matching )
                            question--;
                        }
                        else
                        {
                            break;
                        }
                    }

                    if (left == 0 && right == 0 && question % 2 == 0)
                    {
                        //Console.WriteLine($"{l} {r}");
                        result++;
                    } else if (right == 0 && questionLeft == 0 && question >= left && (question - left) % 2 == 0)
                    {
                        //Console.WriteLine($"{l} {r}");
                        result++;
                    }
                }
            }

            Console.WriteLine(result);
        }
    }
}


fun main(args: Array<String>) {
    val s: String = readLine()!!

    var ans = 0

    for(i in 0 until s.length) {
        var open = 0
        var any = 0
        for(j in i until s.length) {
            when(s[j]) {
                '(' -> ++open
                ')' -> --open
                '?' -> ++any
            }

            while(any > 0 && any > open) {
                open++
                any--
            }

            if(open < 0) break

            if(open == any) ans++
        }
    }

    println(ans)
}


val N = 5007

fun main(args: Array<String>) {
    val s: String = readLine()!!

    val f = Array(N, { Array(N, {false}) })

    for(i in 0 until (s.length - 1))
        if(s[i] != ')' && s[i + 1] != '(')
            f[i][i + 1] = true

    for(i in 0 until s.length) {
        var idx: Int = -1
        for(j in (i - 1) downTo 0 step 2) {
            if(f[j + 1][i - 1]) {
                if(s[j] != ')' && s[i] != '(') f[j][i] = true
                idx = j
            }
            if(f[j][i]) idx = j
            if(idx > 0 && f[j][idx - 1] && f[idx][i]) f[j][i] = true
        }
    }

    var ans = 0
    for(i in 0 until s.length)
        for(j in i+1 until s.length step 2)
            if(f[i][j])
                ans++
    println(ans)
}


#include<stdio.h>
#include<string.h>

char S[5151];

int main() {
	int i, j, ans = 0;
	scanf("%s", S);
	int n = strlen(S);
	for (i = 0; i < n; i++) {
		int l, r;
		l = r = 0;
		for (j = i; j < n; j++) {
			if (S[j] == '(')l++, r++;
			if (S[j] == ')')l--, r--;
			if (S[j] == '?')l--, r++;
			if (l < 0)l += 2;
			if (l > r)break;
			if (l == 0)ans++;
		}
	}
	printf("%d", ans);

	return 0;
}


/* Author Kh. Assaduzzaman Sohan  */

#include<stdio.h>
#include<string.h>
#include<math.h>
#define mod 100000007

char x[50001];

int main()
{
    int i,j,l,r,Ans = 0;
    scanf("%s",x);
    for (i = 0; i < strlen(x); i++)
    {
        l = r = 0;
        for (j = i; j < strlen(x); j++)
        {
            if (x[j] == '(')l++, r++;
            if (x[j] == ')')l--, r--;
            if (x[j] == '?')l--, r++;
            if (l < 0)l += 2;
            if (l > r)break;
            if (l == 0)Ans++;
        }
    }
    printf("%d",Ans);

    return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
	char ch[1000];
	scanf("%s",ch);
	int l=strlen(ch);
	int x,y;
	long long ans=0;
	for(int i=0;i<l;i++)
	{
         x=y=0;
         for(int j=i;j<l;j++)
		 {
		 	if(ch[j]=='(') x++;
		 	else if(ch[j]==')') x--;
		 	else if(ch[j]=='?')
			{
				y++; x--;   //  先把？ 当） （ 不够时在当（
			}
			if(x==0) ans++;
			//if(t>0) continue;
			if(x<0&&y==0) break;//  ? busou wufd bian cheng (;
			if(x<0)
			{
				x+=2;
				y--;
			}
		 }
	}
	printf("%I64d\n",ans);
}


#include<stdio.h>
#include<string.h>
int main()
{
	char ch[1000];
	scanf("%s",ch);
	int l=strlen(ch);
	int x,y;
	int ans=0;
	for(int i=0;i<l;i++)
	{
         x=y=0;
         for(int j=i;j<l;j++)
		 {
		 	if(ch[j]=='(') x++;
		 	else if(ch[j]==')') x--;
		 	else if(ch[j]=='?')
			{
				y++; x--;   //  先把？ 当） （ 不够时在当（
			}
			if(x==0) ans++;
			//if(t>0) continue;
			else if(x<0&&y==0) break;//  ? busou wufd bian cheng (;
			else if(x<0)
			{
				x+=2;
				y--;
			}
		 }
	}
	printf("%d\n",ans);
}


#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	char ch[1000];
	scanf("%s",ch);
	int sum=0;
	for(int i=0;i<strlen(ch);i++)
	{
		if(ch[i]=='?'||ch[i]==')')
		{
			int t=1;
			for(int j=i-1;j>=0;j--)
			{
				if(t<0) break;
				if(ch[j]=='(')
				{
					t=t-1;
					if(t>=0&&(i-j)%2==1) sum++;
				}
				if(ch[j]=='?')
				{
					t=t+1;
					if(t>=0&&(i-j)%2==1) sum++;
				}
				if(ch[j]==')')
				{
					t++;
				}
				//printf("%d     %d    %c\n",t,sum,ch[j]);
			}
		}
	}printf("%d\n",sum);
}


#include<stdio.h>
#include<string.h>
int main()
{
	char ch[10000];
	scanf("%s",ch);
	int l=strlen(ch);
	int x,y;
	long long ans=0;
	for(int i=0;i<l;i++)
	{
         x=0;
         y=0;
         for(int j=i;j<l;j++)
		 {
		 	if(ch[j]=='(') x++;
		 	else if(ch[j]==')') x--;
		 	else if(ch[j]=='?')
			{
				y++; x--;   //  先把？ 当） （ 不够时在当（
			}
			if(x==0) ans++;
			//if(t>0) continue;
			else if(x<0&&y==0) break;//  ? busou wufd bian cheng (;
			if(x<0)
			{
				x+=2;
				y--;
			}
		 }
	}
	printf("%I64d\n",ans);
}


#include <stdio.h>
#include <string.h>

int main () {
    int sol = 0;
    char s[5002];
    scanf("%s",s);
    int i,j;
    int ns=strlen(s);
    for (i = 0; i < ns; i++) {
        int mas = 0, mis = 0;
        for (j = i; j < ns; j++) {
            if (s[j] == ')') {
                mas--;
                mis--;
            }
            if (s[j] == '(') {
                mas++;
                mis++;
            }
            //同时减，同时加可以理解！
            //我理解了，其实这里维护了两个stack
            //就是问号处有两种情况，我们对应处理，
            //遇到（就加入stack,遇到)就退出stack
            //就是维护两种可能的stack!
            if (s[j] == '?') {
                mas++;//就是如果当前？变为（就要加！
                mis--;//如果当前？变为)就要减！
            }
            //printf("mas=%d,mis=%d\n",mas,mis);

            //处理(的stack不能小于零就是不能出现())的情况！
            if (mas < 0)
                break;//为什么这里可以停止了，因为缺少（后面的不用考虑了？
            //等于出现了(多，）少的情况，后面不用处理了！
            if (mis < 0)
                mis += 2;//这里的加２处理的挺好！
            //非常厉害！
            if (mis == 0)
                sol++;//就是当一个stack是０的时候，就是成对的，就可以统计一次！
        }
    }
    printf("%d\n",sol);

    return 0;
}


#include <stdio.h>
#include<string.h>
int main() {
	char s[5002];
	scanf("%s",s);

	int n = strlen(s);

	int ans = 0;

	for (int k = 0; k < n; ++k) {
		int a = 0, b = 0;
		for (int i = k; i < n; ++i) {
			if (s[i] == '(') {
				a++;
				b++;
			}
			if (s[i] == ')') {
				a--;
				b--;
			}
			if (s[i] == '?') {
				a--;//当？被当做)处理！
				b++;//当？被当做(处理！
			}
			if (a < 0)
				a = 0;//为什么这么处理？
			if (b < 0)
				break;//就是）比（多的时候，我们不用处理后面的了！
			if (a == 0 && (b % 2 == 0)) {
                //这个判断要求有点怪怪的！
				//cout << k << " - " << i << endl;
				ans++;
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}


/*
   直觉是用栈，然而实际上用不到栈。

   O(N^2)的复杂度是可以解决问题的。

   枚举区间左端点，从每个左端点尽量向右延伸，在延伸的过程中统计合法区间数。

   那么问题就在于如何判断当前区间是否合法：

   策略：在延伸的过程中统计'('的数量，如果碰到‘?’，也记录下来，并将'?'暂时看为')'，如果碰到右括号且左括号数量不够时，将一个'?'变为左括号。

   当然，如果'('和'?'数量相等时碰到'?'，直接看成'('。因为这种情况下，前面的'?'必须都看做')'。

   维护两个变量 L和 off。L代表左括号的数量，off代表被看为')'的'?'数量。

   当前序列长度为偶数时，答案+1即可。
   */

/*
   Welcome Hacking
   Wish You High Rating
   */
#include<stdio.h>
#include<string.h>
int len,ans;
char s[5010];
int main(){
    scanf("%s",s);
    len=strlen(s);
    for(int i=0;i<len;i++){
        int L=0,off=0;
        for(int j=i;j<len;j++){
            if(s[j]=='(')
                L++;
            else if(s[j]=='?'){
                //数量相同时才把？作为（处理！
                if(L==off)
                    L++;
                else
                //数量不相同时才把？作为)处理！
                    off++;
            }
            else{
                //在相同的情况下，再来了一个)，
                //我们的处理办法是：把前面的某个？看作）来对待取消掉！
                //这个时候L也没有减少？
                //因为把以前作为）的变为（后，与当前）形成了配对，
                //所以L不会改变！
                //这是最优策略，可行策略的实施！
                //就是我们总是有一个可行的策略可以应对，而不是去考虑所有情况！
                //
                //好像还是有点说不通！
                if(L==off)
                    off--;
                else
                    L--;
                if(L<0)
                    break;
                if(off<0)
                    break;
            }
            if((j-i+1)%2==0&&off==L)
                ans++;
        }
    }
    printf("%d\n",ans);
    return 0;
}


#include <stdio.h>
#include<string.h>
int main() {
	char s[5002];
	scanf("%s",s);

	int n = strlen(s);

	int ans = 0;

	for (int k = 0; k < n; ++k) {
		int a = 0, b = 0;
		for (int i = k; i < n; ++i) {
			if (s[i] == '(') {
				a++;
				b++;
			}
			if (s[i] == ')') {
				a--;
				b--;
			}
			if (s[i] == '?') {
				a--;//当？被当做)处理！
				b++;//当？被当做(处理！
			}
            /*
			if (a < 0)
				a = 0;//为什么这么处理？
                */
            //a就是当把所有的？都当做)处理的时候，我们的括号的配对情况！
            //a<0意味着)多出来了！
            //
            //b就是当把所有的？都当做(处理的时候，我们的括号的配对情况！
			if (b < 0)
				break;//就是）比（多的时候，我们不用处理后面的了！
            //b<0意味着在把？当做（处理时，)多出来了！
            //就是说：在已经用（抵消了一部分）之后，）还是多了！
            //我们已经无法处理，后面只能形成)(类型的配对，这是我们不需要出现的情况！
            //b%2可以代表是配对之后是偶数个！
            //一个简单的处理是-a是一个负偶数？
			//if (a == 0 && (b % 2 == 0)) {
			if (a < 0 && ((-a) % 2 == 0)) {
                //a在把？都当做）处理时，)多出来的情况下，只要
                //b在把？当做（处理时，(多出来了
                //我们可以改变一个来产生一个配对产生一个配对！
                //就是说：在问号处，能变为）产生配对的，变为）
                //能变为（产生配对的变为（,做出这样的处理，就会产生每隔一个就可以出现一个配对！
                //这里最后的解释，还是不是那么信服！
				ans++;
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}


#include <stdio.h>
#define MAX_L 10000

char ch[MAX_L];

int main(void)
{
    scanf("%s", ch);
    int ans = 0;
    for (int i = 0; ch[i] != '\0'; i++) {
        int sup = 0, inf = 0;
        for (int j = i; ch[j] != '\0'; j++) {
            if (ch[j] == '(') sup++, inf++;
            else if (ch[j] == ')') sup--, inf--;
            else sup++, inf--;
            if (sup < 0) break;
            if (inf < 0) inf = 0;
            if (((j - i) % 2))
                if (inf == 0) ans++;
        }
    }
    printf("%d\n", ans);
    return 0;
}


// Problem : C. The Monster
// Contest : Codeforces Round #459 (Div. 2)
// URL : https://codeforces.com/contest/918/problem/C
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

import java.io.*;
import java.util.*;

public class a {

	public static void main(String[] args) {
		FastReader scan = new FastReader();
		PrintWriter out = new PrintWriter(System.out);
		Task solver = new Task();
		//int t = scan.nextInt();
		int t = 1;
		for(int i = 1; i <= t; i++) solver.solve(i, scan, out);
		out.close();
	}

	static class Task {

		public void solve(int testNumber, FastReader sc, PrintWriter pw) {
			String str = sc.nextLine();
			int  n = str.length();
			int[] ot = new int[n];
			int[] x = new int[n];
			for(int i=0;i<n;i++){
				if(str.charAt(i)=='('){
					x[i]=1;
				}
				if(str.charAt(i)==')'){
					x[i]=-1;
				}
				if(str.charAt(i)=='?'){
					ot[i]=1;
				}
			}
			int tot = 0;
			loop:
			for(int i=0;i<n;i++){
				int sum1 = 0;
				int sum2 = 0;
				if(str.charAt(i)=='?'){
					sum1--;
					sum2++;
				}
				for(int j = i+1;j<n;j+=2){
					sum1+=ot[j-1];
					sum2+=x[j-1];
					if(sum2+sum1<0)continue loop;
					if(str.charAt(j)=='?'){
						sum2--;
					}
					else{
						sum1+=ot[j];
						sum2+=x[j];
					}

					if(str.charAt(j)=='(')continue;					//pw.println(i+" "+j+" "+sum2+" "+sum1);
					if(sum2+sum1<0)continue loop;
					if(Math.abs(sum2)<=sum1){
						//pw.println(i+" "+j);
						tot++;
					}
					if(str.charAt(j)=='?'){
						sum2++;
						sum1+=ot[j];
						sum2+=x[j];
					}
				}
			}
			pw.println(tot);
		}
	}
	static void shuffle(int[] a) {
		Random get = new Random();
		for (int i = 0; i < a.length; i++) {
			int r = get.nextInt(a.length);
			int temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}

	static void shuffle(long[] a) {
		Random get = new Random();
		for (int i = 0; i < a.length; i++) {
			int r = get.nextInt(a.length);
			long temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		public FastReader(String s) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(new File(s)));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

}


// Problem : C. The Monster
// Contest : Codeforces Round #459 (Div. 2)
// URL : https://codeforces.com/contest/918/problem/C
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

import java.io.*;
import java.util.*;

public class a {

	public static void main(String[] args) {
		FastReader scan = new FastReader();
		PrintWriter out = new PrintWriter(System.out);
		Task solver = new Task();
		//int t = scan.nextInt();
		int t = 1;
		for(int i = 1; i <= t; i++) solver.solve(i, scan, out);
		out.close();
	}

	static class Task {

		public void solve(int testNumber, FastReader sc, PrintWriter pw) {
			String str = sc.nextLine();
			int  n = str.length();
			int[] ot = new int[n];
			int[] x = new int[n];
			for(int i=0;i<n;i++){
				if(str.charAt(i)=='('){
					x[i]=1;
				}
				if(str.charAt(i)==')'){
					x[i]=-1;
				}
				if(str.charAt(i)=='?'){
					ot[i]=1;
				}
			}
			int tot = 0;
			loop:
			for(int i=0;i<n;i++){
				int sum1 = 0;
				int sum2 = 0;
				if(str.charAt(i)=='?'){
					sum1--;
					sum2++;
				}
				for(int j = i+1;j<n;j+=2){
					sum1+=ot[j-1];
					sum2+=x[j-1];
					if(sum2+sum1<0)continue loop;
					if(str.charAt(j)=='?'){
						sum2--;
					}
					else{
						sum1+=ot[j];
						sum2+=x[j];
					}
					//pw.println(i+" "+j+" "+sum2+" "+sum1);
					if(sum2+sum1<0)continue loop;
					if(Math.abs(sum2)<=sum1){
						//pw.println(i+" "+j);
						tot++;
					}

					if(str.charAt(j)=='?'){
						sum2++;
						sum1+=ot[j];
						sum2+=x[j];
					}
				}
			}
			pw.println(tot);
		}
	}
	static void shuffle(int[] a) {
		Random get = new Random();
		for (int i = 0; i < a.length; i++) {
			int r = get.nextInt(a.length);
			int temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}

	static void shuffle(long[] a) {
		Random get = new Random();
		for (int i = 0; i < a.length; i++) {
			int r = get.nextInt(a.length);
			long temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		public FastReader(String s) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(new File(s)));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

}


// Problem : C. The Monster
// Contest : Codeforces Round #459 (Div. 2)
// URL : https://codeforces.com/contest/918/problem/C
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

import java.io.*;
import java.util.*;

public class a {

	public static void main(String[] args) {
		FastReader scan = new FastReader();
		PrintWriter out = new PrintWriter(System.out);
		Task solver = new Task();
		//int t = scan.nextInt();
		int t = 1;
		for(int i = 1; i <= t; i++) solver.solve(i, scan, out);
		out.close();
	}

	static class Task {

		public void solve(int testNumber, FastReader sc, PrintWriter pw) {
			String str = sc.nextLine();
			int  n = str.length();
			int[] ot = new int[n];
			int[] x = new int[n];
			for(int i=0;i<n;i++){
				if(str.charAt(i)=='('){
					x[i]=1;
					ot[i]=1;
				}
				if(str.charAt(i)==')'){
					x[i]=-1;
					ot[i]=-1;
				}
				if(str.charAt(i)=='?'){
					x[i]=-1;
					ot[i]=1;
				}
			}
			int tot = 0;

			loop:
			for(int i=0;i<n;i++){
				int sum1 = 0;
				int sum2 = 0;
				if(str.charAt(i)==')'){continue;
				}
				for(int j = i;j<n;j++){
					sum1+=x[j];
					sum2+=ot[j];
					if(sum1<0)sum1+=2;
					if(sum1>sum2)break;
					if(sum1==0)tot++;
				}
			}
			pw.println(tot);
		}
	}
	static void shuffle(int[] a) {
		Random get = new Random();
		for (int i = 0; i < a.length; i++) {
			int r = get.nextInt(a.length);
			int temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}

	static void shuffle(long[] a) {
		Random get = new Random();
		for (int i = 0; i < a.length; i++) {
			int r = get.nextInt(a.length);
			long temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		public FastReader(String s) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(new File(s)));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

}


import java.util.Scanner;
import java.util.Stack;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine().trim();
        sc.close();

        int count = 0;
        for (int i = 1; i <= s.length(); i++) {
            for (int j = 0; j < i; j++) {
                String str1 = s.substring(j, i);
                String str2 = reverse(str1);
                if ((j - i) % 2 == 1) {
                    continue;
                }
                if (isValid(str1) || isValid(str2)) {
                    count++;
                }
            }
        }

        System.out.println(count);
    }

    private static String reverse(String s) {
        StringBuilder sb = new StringBuilder();
        for (int i = s.length() - 1; i >= 0; i--) {
            char c = s.charAt(i);
            if (c == '(') {
                sb.append(')');
            } else if (c == ')') {
                sb.append('(');
            } else {
                sb.append('?');
            }

        }
        return sb.toString();
    }

    private static boolean isValid(String s) {
        Stack<Character> stack = new Stack<>();
        for (char c :
                s.toCharArray()) {
            if (stack.isEmpty() || c == '(') {
                stack.push(c);
            } else if (c == ')') {
                if (stack.peek() == '(' || stack.peek() == '?') {
                    stack.pop();
                } else {
                    // To-do
                    return false;
                }
            } else if (c == '?') {
                if (stack.peek() == '?') {
                    stack.pop();
                } else {
                    stack.push(c);
                }
            }
        }
        return stack.isEmpty();
    }
}


import java.util.Scanner;
import java.util.Stack;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine().trim();
        sc.close();

        // wrong: because ? can be { or/and } (at the same time)
        // mytry(s);

        // we need to consider each substring
        int count = 0;
        for (int i = 0; i < s.length() - 1; i++) {
            if (s.charAt(i) == ')') {
                continue;
            }
            int layer = 0;
            int possible = 1;
            for (int j = i + 1; j <= s.length(); j++) {
                if(j == i + 1 && s.charAt(j - 1) == '?'){
                    layer = 1;
                    continue;
                }
                if (possible <= 0) {
                    break;
                }
                if (s.charAt(j - 1) == '(') {
                    layer++;
                } else if (s.charAt(j - 1) == ')') {
                    layer--;
                } else {
                    // ? case
                    layer--;
                    possible++;

                }
                if (layer == 0) {
                    count++;
                } else if (layer < 0) {
                    layer += 2;
                    possible--;
                }
            }
        }
        System.out.println(count);
    }

    private static void mytry(String s) {
        int count = 0;
        for (int i = 1; i <= s.length(); i++) {
            for (int j = 0; j < i; j++) {
                String str1 = s.substring(j, i);
                String str2 = reverse(str1);
                if ((j - i) % 2 == 1) {
                    continue;
                }
                if (isValid(str1) || isValid(str2)) {
                    count++;
                }
            }
        }

        System.out.println(count);
    }

    private static String reverse(String s) {
        StringBuilder sb = new StringBuilder();
        for (int i = s.length() - 1; i >= 0; i--) {
            char c = s.charAt(i);
            if (c == '(') {
                sb.append(')');
            } else if (c == ')') {
                sb.append('(');
            } else {
                sb.append('?');
            }

        }
        return sb.toString();
    }

    private static boolean isValid(String s) {
        int n = s.length();
        while (n != 0) {
            String remain = check(s);
            if (remain.length() == n) {
                return false;
            }
            n = remain.length();
            s = remain;
        }
        return true;
    }

    private static String check(String s) {
        Stack<Character> stack = new Stack<>();
        for (char c :
                s.toCharArray()) {
            if (stack.isEmpty() || c == '(') {
                stack.push(c);
            } else if (c == ')') {
                if (stack.peek() == '(' || stack.peek() == '?') {
                    stack.pop();
                } else {
                    // To-do
                    return s;
                }
            } else if (c == '?') {
                if (stack.peek() == '?') {
                    stack.pop();
                } else {
                    stack.push(c);
                }
            }
        }
        StringBuilder sb = new StringBuilder();
        while (!stack.isEmpty()) {
            sb.append(stack.pop());
        }
        return sb.toString();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.stream.Stream;

public class Solution implements Runnable {

	static final double time = 1e9;
	static final int MOD = (int) 1e9 + 7;
	static final long mh = Long.MAX_VALUE;
	static final Reader in = new Reader();
	static final PrintWriter out = new PrintWriter(System.out);
	StringBuilder answer = new StringBuilder();

	public static void main(String[] args) {
		new Thread(null, new Solution(), "persefone", 1 << 28).start();
	}

	@Override
	public void run() {
		long start = System.nanoTime();
		solve();
		printf();
		long elapsed = System.nanoTime() - start;
		// out.println("stamp : " + elapsed / time);
		// out.println("stamp : " + TimeUnit.SECONDS.convert(elapsed,
		// TimeUnit.NANOSECONDS));
		close();
	}

	void solve() {
		char[] s = in.next().toCharArray();
		int n = s.length;
		boolean[][] correct = new boolean[n][n];
		for (int i = 0; i < n - 1; i++) correct[i][i + 1] = true;
		long ans = 0;

		int[] dp = new int[n];
		for (int i = 1; i < n; i++) {
			if (s[i] == '(') continue;
			for (int j = i - 1; j > -1; j -= 2) {
				if (s[j] != ')') {
					correct[i][j] = correct[i - 1][j + 1];
					if (correct[i][j]) {
						ans++;
						if (j > 1) ans += dp[j - 1];
						dp[i]++;
					}
				}
			}
		}

		printf(ans);
	}

	public static int[] shuffle(int[] a, Random gen) {
		for (int i = 0, n = a.length; i < n; i++) {
			int ind = gen.nextInt(n - i) + i;
			int d = a[i];
			a[i] = a[ind];
			a[ind] = d;
		}
		return a;
	}

	public static int[] shrinkX(int[] a) {
		int n = a.length;
		long[] b = new long[n];
		for (int i = 0; i < n; i++)
			b[i] = (long) a[i] << 32 | i;
		Arrays.sort(b);
		int[] ret = new int[n];
		int p = 0;
		ret[0] = (int) (b[0] >> 32);
		for (int i = 0; i < n; i++) {
			if (i > 0 && (b[i] ^ b[i - 1]) >> 32 != 0) {
				p++;
				ret[p] = (int) (b[i] >> 32);
			}
			a[(int) b[i]] = p;
		}
		return Arrays.copyOf(ret, p + 1);
	}

	int pow(int a, int b, int p) {
		long ans = 1, base = a;
		while (b > 0) {
			if ((b & 1) > 0) {
				ans *= base %= p;
			}
			base *= base %= p;
			b >>= 1;
		}
		return (int) ans;
	}

	public static int[] enumLowestPrimeFactors(int n) {
		int tot = 0;
		int[] lpf = new int[n + 1];
		int u = n + 32;
		double lu = Math.log(u);
		int[] primes = new int[(int) (u / lu + u / lu / lu * 1.5)];
		for (int i = 2; i <= n; i++)
			lpf[i] = i;
		for (int p = 2; p <= n; p++) {
			if (lpf[p] == p)
				primes[tot++] = p;
			int tmp;
			for (int i = 0; i < tot && primes[i] <= lpf[p] && (tmp = primes[i] * p) <= n; i++) {
				lpf[tmp] = primes[i];
			}
		}
		return lpf;
	}

	public static int[] enumNumDivisorsFast(int n, int[] lpf) {
		int[] nd = new int[n + 1];
		nd[1] = 1;
		for (int i = 2; i <= n; i++) {
			int j = i, e = 0;
			while (j % lpf[i] == 0) {
				j /= lpf[i];
				e++;
			}
			nd[i] = nd[j] * (e + 1);
		}
		return nd;
	}

	boolean isPrime(long n) {

		for (int i = 2; 1l * i * i <= n; i++)
			if (n % i == 0)
				return false;
		return true;
	}

	void printf() {
		out.print(answer);
	}

	void close() {
		out.close();
	}

	void printf(Stream<?> str) {
		str.forEach(o -> add(o, " "));
		add("\n");
	}

	void printf(Object... obj) {
		printf(false, obj);
	}

	void printfWithDescription(Object... obj) {
		printf(true, obj);
	}

	private void printf(boolean b, Object... obj) {

		if (obj.length > 1) {
			for (int i = 0; i < obj.length; i++) {
				if (b)
					add(obj[i].getClass().getSimpleName(), " - ");
				if (obj[i] instanceof Collection<?>) {
					printf((Collection<?>) obj[i]);
				} else if (obj[i] instanceof int[][]) {
					printf((int[][]) obj[i]);
				} else if (obj[i] instanceof long[][]) {
					printf((long[][]) obj[i]);
				} else if (obj[i] instanceof double[][]) {
					printf((double[][]) obj[i]);
				} else
					printf(obj[i]);
			}
			return;
		}

		if (b)
			add(obj[0].getClass().getSimpleName(), " - ");
		printf(obj[0]);
	}

	void printf(Object o) {
		if (o instanceof int[])
			printf(Arrays.stream((int[]) o).boxed());
		else if (o instanceof char[])
			printf(new String((char[]) o));
		else if (o instanceof long[])
			printf(Arrays.stream((long[]) o).boxed());
		else if (o instanceof double[])
			printf(Arrays.stream((double[]) o).boxed());
		else if (o instanceof boolean[]) {
			for (boolean b : (boolean[]) o)
				add(b, " ");
			add("\n");
		} else
			add(o, "\n");
	}

	void printf(int[]... obj) {
		for (int i = 0; i < obj.length; i++)
			printf(obj[i]);
	}

	void printf(long[]... obj) {
		for (int i = 0; i < obj.length; i++)
			printf(obj[i]);
	}

	void printf(double[]... obj) {
		for (int i = 0; i < obj.length; i++)
			printf(obj[i]);
	}

	void printf(boolean[]... obj) {
		for (int i = 0; i < obj.length; i++)
			printf(obj[i]);
	}

	void printf(Collection<?> col) {
		printf(col.stream());
	}

	<T, K> void add(T t, K k) {
		if (t instanceof Collection<?>) {
			((Collection<?>) t).forEach(i -> add(i, " "));
		} else if (t instanceof Object[]) {
			Arrays.stream((Object[]) t).forEach(i -> add(i, " "));
		} else
			add(t);
		add(k);
	}

	<T> void add(T t) {
		answer.append(t);
	}

	@SuppressWarnings("unchecked")
	<T extends Comparable<? super T>> T min(T... t) {
		if (t.length == 0)
			return null;
		T m = t[0];
		for (int i = 1; i < t.length; i++)
			if (t[i].compareTo(m) < 0)
				m = t[i];
		return m;
	}

	@SuppressWarnings("unchecked")
	<T extends Comparable<? super T>> T max(T... t) {
		if (t.length == 0)
			return null;
		T m = t[0];
		for (int i = 1; i < t.length; i++)
			if (t[i].compareTo(m) > 0)
				m = t[i];
		return m;
	}

	int gcd(int a, int b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	long gcd(long a, long b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	long lcm(int a, int b) {
		return (1l * a * b / gcd(a, b));
	}

	long lcm(long a, long b) {
		if (a > Long.MAX_VALUE / b)
			throw new RuntimeException();
		return a * b / gcd(a, b);
	}

	// c = gcd(a, b) -> extends gcd method: ax + by = c <----> (b % a)p + q = c;
	int[] ext_gcd(int a, int b) {
		if (b == 0)
			return new int[] { a, 1, 0 };
		int[] vals = ext_gcd(b, a % b);
		int d = vals[0]; // gcd
		int p = vals[2]; //
		int q = vals[1] - (a / b) * vals[2];
		return new int[] { d, p, q };
	}

	// find any solution of the equation: ax + by = c using extends gcd
	boolean find_any_solution(int a, int b, int c, int[] root) {
		int[] vals = ext_gcd(Math.abs(a), Math.abs(b));
		if (c % vals[0] != 0)
			return false;
		printf(vals);
		root[0] = c * vals[1] / vals[0];
		root[1] = c * vals[2] / vals[0];
		if (a < 0)
			root[0] *= -1;
		if (b < 0)
			root[1] *= -1;
		return true;
	}

	int mod(int x) {
		return x % MOD;
	}

	int mod(int x, int y) {
		return mod(mod(x) + mod(y));
	}

	long mod(long x) {
		return x % MOD;
	}

	long mod(long x, long y) {
		return mod(mod(x) + mod(y));
	}

	int lw(long[] f, int l, int r, long k) {
		int R = r, m = 0;
		while (l <= r) {
			m = l + r >> 1;
			if (m == R)
				return m;
			if (f[m] >= k)
				r = m - 1;
			else
				l = m + 1;
		}
		return l;
	}

	int up(long[] f, int l, int r, long k) {
		int R = r, m = 0;
		while (l <= r) {
			m = l + r >> 1;
			if (m == R)
				return m;
			if (f[m] > k)
				r = m - 1;
			else
				l = m + 1;
		}
		return l;
	}

	int lw(int[] f, int l, int r, int k) {
		int R = r, m = 0;
		while (l <= r) {
			m = l + r >> 1;
			if (m == R)
				return m;
			if (f[m] >= k)
				r = m - 1;
			else
				l = m + 1;
		}
		return l;
	}

	int up(int[] f, int l, int r, int k) {
		int R = r, m = 0;
		while (l <= r) {
			m = l + r >> 1;
			if (m == R)
				return m;
			if (f[m] > k)
				r = m - 1;
			else
				l = m + 1;
		}
		return l;
	}

	<K extends Comparable<K>> int lw(List<K> li, int l, int r, K k) {
		int R = r, m = 0;
		while (l <= r) {
			m = l + r >> 1;
			if (m == R)
				return m;
			if (li.get(m).compareTo(k) >= 0)
				r = m - 1;
			else
				l = m + 1;
		}
		return l;
	}

	<K extends Comparable<K>> int up(List<K> li, int l, int r, K k) {
		int R = r, m = 0;
		while (l <= r) {
			m = l + r >> 1;
			if (m == R)
				return m;
			if (li.get(m).compareTo(k) > 0)
				r = m - 1;
			else
				l = m + 1;
		}
		return l;
	}

	<K extends Comparable<K>> int bs(List<K> li, int l, int r, K k) {
		while (l <= r) {
			int m = l + r >> 1;
			if (li.get(m) == k)
				return m;
			else if (li.get(m).compareTo(k) < 0)
				l = m + 1;
			else
				r = m - 1;
		}
		return -1;
	}

	long calc(int base, int exponent, int p) {
		if (exponent == 0)
			return 1;
		if (exponent == 1)
			return base % p;
		long m = calc(base, exponent >> 1, p);
		if (exponent % 2 == 0)
			return (m * m) % p;
		return 1l * base * m % p * m % p;
	}

	long calc(int base, long exponent, int p) {
		if (exponent == 0)
			return 1;
		if (exponent == 1)
			return base % p;
		long m = calc(base, exponent >> 1, p);
		if (exponent % 2 == 0)
			return (m * m) % p;
		return 1l * base * m % p * m % p;
	}

	long calc(long base, long exponent, int p) {
		if (exponent == 0)
			return 1;
		if (exponent == 1)
			return base % p;
		long m = calc(base, exponent >> 1, p);
		if (exponent % 2 == 0)
			return (m * m) % p;
		return base * m % p * m % p;
	}

	long power(int base, int exponent) {
		if (exponent == 0)
			return 1;
		long m = power(base, exponent / 2);
		if (exponent % 2 == 0)
			return m * m;
		return base * m * m;
	}

	void swap(int[] a, int i, int j) {
		a[i] ^= a[j];
		a[j] ^= a[i];
		a[i] ^= a[j];
	}

	void swap(long[] a, int i, int j) {
		long tmp = a[i];
		a[i] = a[j];
		a[j] = tmp;
	}

	static class Pair<K extends Comparable<? super K>, V extends Comparable<? super V>>
			implements Comparable<Pair<K, V>> {
		private K k;
		private V v;

		Pair() {
		}

		Pair(K k, V v) {
			this.k = k;
			this.v = v;
		}

		K getK() {
			return k;
		}

		V getV() {
			return v;
		}

		void setK(K k) {
			this.k = k;
		}

		void setV(V v) {
			this.v = v;
		}

		void setKV(K k, V v) {
			this.k = k;
			this.v = v;
		}

		@SuppressWarnings("unchecked")
		@Override
		public boolean equals(Object o) {
			if (this == o)
				return true;
			if (o == null || !(o instanceof Pair))
				return false;
			Pair<K, V> p = (Pair<K, V>) o;
			return k.compareTo(p.k) == 0 && v.compareTo(p.v) == 0;
		}

		@Override
		public int hashCode() {
			int hash = 31;
			hash = hash * 89 + k.hashCode();
			hash = hash * 89 + v.hashCode();
			return hash;
		}

		@Override
		public int compareTo(Pair<K, V> pair) {
			return k.compareTo(pair.k) == 0 ? v.compareTo(pair.v) : k.compareTo(pair.k);
		}

		@Override
		public Pair<K, V> clone() {
			return new Pair<K, V>(this.k, this.v);
		}

		@Override
		public String toString() {
			return String.valueOf(k).concat(" ").concat(String.valueOf(v)).concat("\n");
		}
	}

	static class Reader {
		private BufferedReader br;
		private StringTokenizer st;

		Reader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			try {
				while (st == null || !st.hasMoreTokens()) {
					st = new StringTokenizer(br.readLine());
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		int[] nextIntArray(int n) {
			int[] arr = new int[n];
			for (int i = 0; i < n; i++)
				arr[i] = nextInt();
			return arr;
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String nextLine() {
			String s = "";
			try {
				s = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return s;
		}
	}
}


import java.io.*;
import java.util.*;
import java.util.stream.Stream;
import java.util.Map.Entry;

public class Main implements Runnable {
    static final int MOD = (int) 1e9 + 7;
    static final int MI = (int) 1e9;
    static final long ML = (long) 1e18;
    static final Reader in = new Reader();
    static final PrintWriter out = new PrintWriter(System.out);
    StringBuilder answer = new StringBuilder();

    public static void main(String[] args) {
        new Thread(null, new Main(), "persefone", 1 << 32).start();
    }

    @Override
    public void run() {
        solve();
        printf();
        flush();
    }

    void solve() {
        char[] s = in.next().toCharArray();
        int n = s.length;
        int ans = 0;
        for (int i = 0; i < n; i++) {
            int balance = 0, questions = 0;
            for (int j = i; j < n; j++) {
                if (s[j] == '?') {
                    questions++;
                } else {
                    balance += s[j] == '(' ? 1 : -1;
                }
                if (questions > balance) {
                    questions--;
                    balance++;
                }
                if (questions + balance < 0) break;
                if ((j - i) % 2 == 1 && questions == balance) ans++;
            }
        }
        printf(ans);
    }

    void printf() {
        out.print(answer);
    }

    void close() {
        out.close();
    }

    void flush() {
        out.flush();
    }

    void printf(Stream<?> str) {
        str.forEach(o -> add(o, " "));
        add("\n");
    }

    void printf(Object... obj) {
        printf(false, obj);
    }

    void printfWithDescription(Object... obj) {
        printf(true, obj);
    }

    private void printf(boolean b, Object... obj) {

        if (obj.length > 1) {
            for (int i = 0; i < obj.length; i++) {
                if (b) add(obj[i].getClass().getSimpleName(), " - ");
                if (obj[i] instanceof Collection<?>) {
                    printf((Collection<?>) obj[i]);
                } else if (obj[i] instanceof int[][]) {
                    printf((int[][]) obj[i]);
                } else if (obj[i] instanceof long[][]) {
                    printf((long[][]) obj[i]);
                } else if (obj[i] instanceof double[][]) {
                    printf((double[][]) obj[i]);
                } else printf(obj[i]);
            }
            return;
        }

        if (b) add(obj[0].getClass().getSimpleName(), " - ");
        printf(obj[0]);
    }

    void printf(Object o) {
        if (o instanceof int[])
            printf(Arrays.stream((int[]) o).boxed());
        else if (o instanceof char[])
            printf(new String((char[]) o));
        else if (o instanceof long[])
            printf(Arrays.stream((long[]) o).boxed());
        else if (o instanceof double[])
            printf(Arrays.stream((double[]) o).boxed());
        else if (o instanceof boolean[]) {
            for (boolean b : (boolean[]) o) add(b, " ");
            add("\n");
        } else
            add(o, "\n");
    }

    void printf(int[]... obj) {
        for (int i = 0; i < obj.length; i++) printf(obj[i]);
    }

    void printf(long[]... obj) {
        for (int i = 0; i < obj.length; i++) printf(obj[i]);
    }

    void printf(double[]... obj) {
        for (int i = 0; i < obj.length; i++) printf(obj[i]);
    }

    void printf(boolean[]... obj) {
        for (int i = 0; i < obj.length; i++) printf(obj[i]);
    }

    void printf(Collection<?> col) {
        printf(col.stream());
    }

    <T, K> void add(T t, K k) {
        if (t instanceof Collection<?>) {
            ((Collection<?>) t).forEach(i -> add(i, " "));
        } else if (t instanceof Object[]) {
            Arrays.stream((Object[]) t).forEach(i -> add(i, " "));
        } else
            add(t);
        add(k);
    }

    <T> void add(T t) {
        answer.append(t);
    }

    static class Reader {
        private BufferedReader br;
        private StringTokenizer st;

        Reader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        Reader(String fileName) throws FileNotFoundException {
            br = new BufferedReader(new FileReader(fileName));
        }

        boolean isReady() throws IOException {
            return br.ready();
        }

        String next() {
            try {
                while (st == null || !st.hasMoreTokens()) {
                    st = new StringTokenizer(br.readLine());
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++)
                arr[i] = nextInt();
            return arr;
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        String nextLine() {
            String s = "";
            try {
                s = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return s;
        }
    }
}


import java.util.HashSet;
import java.util.Scanner;

public class Task918C {

    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final String s = scanner.nextLine();

        final HashSet<Integer> hashSet = new HashSet<Integer>(100);

        for (int i1 = 0; i1 < s.length(); i1++) {
            int count = 0;
            int var = 0;
            int i2 = i1;
            while (i2 < s.length()) {
                final char c = s.charAt(i2);
                if (c == '?') {
                    if (count == 0) count++;
                    else var++;
                } else if (c == '(') {
                    count++;
                } else if (c == ')') {
                    count--;
                }
                i2++;
                if (count + var < 0) break;
                if ((i2-i1) % 2 == 0 && count <= var) {
                    hashSet.add(i1 * 10000 + i2);
                    // System.out.println(i1 + " " + i2 + " " + s.substring(i1, i2));
                    // result++;
                }
            }
        }

        // System.out.println();

        int result = 0;
        for (int i1 = s.length(); i1 > 0; i1--) {
            int count = 0;
            int var = 0;
            int i2 = i1 - 1;
            while (i2 >= 0) {
                final char c = s.charAt(i2);
                if (c == '?') {
                    if (count == 0) count++;
                    else var++;
                } else if (c == ')') {
                    count++;
                } else if (c == '(') {
                    count--;
                }
                if (count + var < 0) break;
                if ((i1-i2) % 2 == 0 && count <= var) {
                    if (hashSet.contains(i2 * 10000 + i1)) {
                        result++;
                        // System.out.println(i2 + " " + i1 + " " + s.substring(i2, i1));
                    }
                }
                i2--;
            }
        }

        System.out.println(result);
    }
}


import java.util.Scanner;

public class Task918C {

    public static boolean IsCorrect(final String s, final int i1, final int i2, int count) {
        if (count < 0) return false;
        if (i1 > i2) return count == 0;
        else {
            final char c = s.charAt(i1);
            if (c == '?') return IsCorrect(s, i1+1, i2, count+1) || IsCorrect(s, i1+1, i2, count-1);
            else {
                if (c == '(') count++;
                else count--;
                return IsCorrect(s, i1+1, i2, count);
            }
        }
    }

    public static boolean IsBeatiful(final String s, final int i1, final int i2) {
        return (i2 - i1) % 2 == 1 && IsCorrect(s, i1, i2, 0);
    }

    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final String s = scanner.nextLine();

        int result = 0;
        for (int i1 = 0; i1 < s.length(); i1++) {
            for (int i2 = i1; i2 < s.length(); i2++) {
                if (IsBeatiful(s, i1, i2)) result++;
            }
        }
        System.out.println(result);
    }
}


import java.util.Scanner;

public class Task918C {

    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final String s = scanner.nextLine();

        final boolean[][] isCorrect = new boolean[s.length()][s.length() + 1];

        for (int i1 = 0; i1 < s.length(); i1++) {
            int count = 0;
            int var = 0;
            int i2 = i1;
            while (i2 < s.length()) {
                final char c = s.charAt(i2);
                if (c == '?') {
                    if (count == 0) count++;
                    else var++;
                } else if (c == '(') {
                    count++;
                } else if (c == ')') {
                    count--;
                }
                i2++;
                if (count + var < 0) break;
                if ((i2-i1) % 2 == 0 && count <= var) {
                    isCorrect[i1][i2] = true;
                    // System.out.println(i1 + " " + i2 + " " + s.substring(i1, i2));
                    // result++;
                }
            }
        }

        // System.out.println();

        int result = 0;
        for (int i1 = s.length(); i1 > 0; i1--) {
            int count = 0;
            int var = 0;
            int i2 = i1 - 1;
            while (i2 >= 0) {
                final char c = s.charAt(i2);
                if (c == '?') {
                    if (count == 0) count++;
                    else var++;
                } else if (c == ')') {
                    count++;
                } else if (c == '(') {
                    count--;
                }
                if (count + var < 0) break;
                if ((i1-i2) % 2 == 0 && count <= var) {
                    if (isCorrect[i2][i1]) {
                        result++;
                        // System.out.println(i2 + " " + i1 + " " + s.substring(i2, i1));
                    }
                }
                i2--;
            }
        }

        System.out.println(result);
    }
}


import java.util.Scanner;

public class Task918C {

    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final String s = scanner.nextLine();

        int result = 0;
        for (int i1 = 0; i1 < s.length(); i1++) {
            int count = 0;
            int var = 0;
            int i2 = i1;
            while (i2 < s.length()) {
                final char c = s.charAt(i2);
                if (c == '?') {
                    if (count == 0) count++;
                    else var++;
                } else if (c == '(') {
                    count++;
                } else if (c == ')') {
                    count--;
                }
                i2++;
                if (count + var < 0) break;
                if ((i2-i1) % 2 == 0 && count <= var && c != '(') {
                    System.out.println(i1 + " " + i2 + " " + s.substring(i1, i2));
                    result++;
                }
            }
        }
        System.out.println(result);
    }
}


import java.util.Scanner;

public class Task918C {

    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final String s = scanner.nextLine();

        int result = 0;
        for (int i1 = 0; i1 < s.length(); i1++) {
            int count = 0;
            int var = 0;
            int i2 = i1;
            while (i2 < s.length()) {
                final char c = s.charAt(i2);
                if (c == '?') {
                    if (count == 0) count++;
                    else var++;
                } else if (c == '(') {
                    count++;
                } else if (c == ')') {
                    count--;
                }
                i2++;
                if (count + var < 0) break;
                if ((i2-i1) % 2 == 0 && count <= var && c != '(') {
                    // System.out.println(i1 + " " + i2 + " " + s.substring(i1, i2));
                    result++;
                }
            }
        }
        System.out.println(result);
    }
}


import java.util.HashSet;
import java.util.Scanner;

public class Task918C {

    public static int GetNumBeatufulStrings(final String s, final int i1, int i2, int count, final HashSet<Integer> hashSet) {
        if (count < 0) return 0;
        else {
            int num = 0;
            if (i1 != i2 && count == 0) {
                if (!hashSet.contains(i1 * 10000 + i2)) {
                    // System.out.println(i1 + " " + i2);
                    num++;
                    hashSet.add(i1 * 10000 + i2);
                }
            }

            while (i2 < s.length()) {
                final char c = s.charAt(i2);
                if (c == '?') {
                    num += GetNumBeatufulStrings(s, i1, i2+1, count+1, hashSet) + GetNumBeatufulStrings(s, i1, i2+1, count-1, hashSet);
                    break;
                } else if (c == '(') count++;
                else count--;
                i2++;

                if (i1 != i2 && count == 0) {
                    if (!hashSet.contains(i1 * 10000 + i2)) {
                        // System.out.println(i1 + " " + i2);
                        num++;
                        hashSet.add(i1 * 10000 + i2);
                    }
                }
                else if (count < 0) break;
            }
            return num;
        }
    }

    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final String s = scanner.nextLine();

        int result = 0;
        final HashSet<Integer> hashSet = new HashSet<Integer>();
        for (int i = 0; i < s.length(); i++) {
            result += GetNumBeatufulStrings(s, i, i, 0, hashSet);
        }
        System.out.println(result);
    }
}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class C918{

	void solve()
	{
		char[] s = ca();
		int n = s.length;
		int cn = 0;
		for(int l=0;l<n;l++)
		{
			int scr = 0;
			int qms = 0;
			for(int r=l;r<n;r++)
			{
				if(s[r] == '(')
					scr++;
				else if(s[r] == ')')
				{
					if(scr > 0) // force close
						scr--;
					else if(qms > 0) // '?' (currently a ')') --> '('
					{
						qms--;
						scr++;
					}
					else // no valid sequence beyond r
						break;
				}
				else // '?'
				{
					if(scr == 0) // force open
						scr++;
					else // '?' --> ')'
					{
						scr--;
						qms++;
					}
				}
				if(scr == 0)
					cn++;
			}
		}
		out.println(cn);
	}

	public static void main(String[] args){new C918().run();}

	private byte[] bufferArray = new byte[1024];
	private int bufLength = 0;
	private int bufCurrent = 0;
	InputStream inputStream;
	PrintWriter out;

	public void run()
	{
		inputStream = System.in;
		out = new PrintWriter(System.out);
		solve();
		out.flush();
	}

	int nextByte()
	{
		if(bufLength == -1)
			throw new InputMismatchException();
		if(bufCurrent >= bufLength)
		{
			bufCurrent = 0;
			try
			{bufLength = inputStream.read(bufferArray);}
			catch(IOException e)
			{ throw new InputMismatchException();}
			if(bufLength <= 0)
				return -1;
		}
		return bufferArray[bufCurrent++];
	}

	boolean isSpaceChar(int x)	{return (x < 33 || x > 126);}

	boolean isDigit(int x)	{return (x >= '0' && x <= '9');}

	int nextNonSpace()
	{
		int x;
		while((x=nextByte()) != -1 && isSpaceChar(x));
		return x;
	}

	int ni()
	{
		long ans = nl();
		if (ans >= Integer.MIN_VALUE && ans <= Integer.MAX_VALUE)
			return (int)ans;
		throw new InputMismatchException();
	}

	long nl()
	{
		long ans = 0;
		boolean neg = false;
		int x = nextNonSpace();
		if(x == '-')
		{
			neg = true;
			x = nextByte();
		}
		while(!isSpaceChar(x))
		{
			if(isDigit(x))
			{
				ans = ans * 10 + x -'0';
				x = nextByte();
			}
			else
				throw new InputMismatchException();
		}
		return neg ? -ans : ans;
	}

	String ns()
	{
		StringBuilder sb = new StringBuilder();
		int x = nextNonSpace();
		while(!isSpaceChar(x))
		{
			sb.append((char)x);
			x = nextByte();
		}
		return sb.toString();
	}

	char nc()	{ return (char)nextNonSpace();}

	double nd()	{ return (double)Double.parseDouble(ns()); }

	char[] ca()	{ return ns().toCharArray();}

	char[][] ca(int n)
	{
		char[][] ans = new char[n][];
		for(int i=0;i<n;i++)
			ans[i] = ca();
		return ans;
	}

	int[] ia(int n)
	{
		int[] ans = new int[n];
		for(int i=0;i<n;i++)
			ans[i] = ni();
		return ans;
	}

	void db(Object... o) {System.out.println(Arrays.deepToString(o));}

}


import java.io.*;
import java.util.*;
import java.math.BigInteger;
public class Main {

    static class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }

    public static void main(String[] args) throws IOException {
    	Scanner in = new Scanner(System.in);
    	String s = in.next();
    	int n = s.length();
    	boolean ans[][] = new boolean[n][n];
    	for(int i=0; i<n; i++){
    		for(int j=i+1; j<n; j+=2){
    			ans[i][j] = true;
	    	}
    	}
    	int open = 0;
    	for(int i=0; i<n; i++){
    		open=0;
    		for(int j=i; j<n; j++){
    			if(s.charAt(j)==')')
    				open++;
    			else
    				open--;
    			if(open>0){
    				for(int k=j; k<n; k++)
    					ans[i][k] = false;
    				break;
    			}
    		}
    	}
    	for(int i=n-1; i>=0; i--){
    		open=0;
    		for(int j=i; j>=0; j--){
    			if(s.charAt(j)=='(')
    				open++;
    			else
    				open--;
    			if(open>0){
    				for(int k=j; k>=0; k--)
    					ans[k][i] = false;
    				break;
    			}
    		}
    	}
    	int answ = 0;
    	for(int i=0; i<n; i++){
    		for(int j=i+1; j<n; j+=2){
    			if(ans[i][j]){
    				answ++;
    			}
    		}
    	}
    	System.out.println(answ);
    }
}


import java.io.*;
import java.util.*;
import java.math.BigInteger;
public class Main {

    static class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }

    public static void main(String[] args) throws IOException {
    	Scanner in = new Scanner(System.in);
    	String s = in.next();
    	int ans = 0;
    	int open[] = new int[s.length()+1];
    	int close[] = new int[s.length()+1];
    	int que[] = new int[s.length()+1];
    	for(int i=1; i<=s.length(); i++){
    		open[i] = open[i-1];
    		close[i] = close[i-1];
    		que[i] = que[i-1];
    		if(s.charAt(i-1)=='('){
    			open[i]++;
    		}
    		else if(s.charAt(i-1)==')'){
    			close[i]++;
    		}
    		else{
    			que[i]++;
    		}
    	}
    	for(int i=1; i<=s.length(); i++){
    		for(int j=i+1; j<=s.length(); j++){
    			if((j-i+1)%2==1){
    				continue;
    			}
				if(open[j] - open[i-1] + que[j] - que[i-1] - close[j] + close[i-1] >= 0 && s.charAt(i-1)!=')' && s.charAt(j-1)!='(' && close[j] - close[i-1] + que[j] - que[i-1] - open[j] + open[i-1] >=0){

					ans++;
				}
	    	}
    	}
    	System.out.println(ans);
    }
}


package com.programming;

import java.util.*;
import java.math.*;
import java.io.*;
import java.util.Collections;

public class Solution {

    static class Solver {

        Solver() {
        }

        public void solve(FastScanner sc, PrintWriter out) throws IOException {
            char[] arr = sc.nextLine().toCharArray();
            int n = arr.length;
            int ans = 0;
            for(int i = 0; i < n; i++) {
                int score = 0;
                int qmarks = 0;
                for(int j = i; j < n; j++) {
                    if(arr[j] == '(') {
                        ++score;
                    } else if(arr[j] == ')') {
                        --score;
                    } else {
                        qmarks++;
                    }

                    if(score >= 0 && qmarks > score) {
                        --qmarks;
                        score++;
                    }

                    if(score >= 0 && qmarks >= score && ((j+1-i) % 2 == 0)) {
                        ++ans;
                    }
                }
            }
            out.println(ans);
        }
    }
    public static void main(String[] args) throws IOException{
        FastScanner scanner = new FastScanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        (new Solver()).solve(scanner, out);
        out.flush();

    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner(InputStream stream) {
            try {
                br = new BufferedReader(new InputStreamReader(stream));
            } catch(Exception e) {
                e.printStackTrace();
            }
        }

        boolean hasNextToken() {
            if(st == null) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch(IOException e) {

                }
            }
            return st.hasMoreTokens();
        }

        String next() {
            while(st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch(IOException e) {
                    e.printStackTrace();
                }
            }

            return st.nextToken();
        }

        String nextLine() throws IOException{
            return br.readLine();
        }

        byte nextByte() {
            return Byte.parseByte(next());
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}


import java.util.*;
import java.math.*;
import java.io.*;
import java.util.Collections;

public class Solution {

    static class Solver {

        Solver() {
        }

        public void solve(FastScanner sc, PrintWriter out) throws IOException {
            char[] arr = sc.nextLine().toCharArray();
            int n = arr.length;
            int ans = 0;
            for(int i = 0; i < n; i++) {
                int score = 0;
                int qmarks = 0;
                for(int j = i; j < n; j++) {
                    if(arr[j] == '(') {
                        ++score;
                    } else if(arr[j] == ')') {
                        --score;
                    } else {
                        qmarks++;
                    }

                    if(score >= 0 && qmarks > score) {
                        --qmarks;
                        score++;
                    }

                    if(score >= 0 && qmarks >= score && ((j+1-i) % 2 == 0)) {
                        ++ans;
                    }
                }
            }
            out.println(ans);
        }
    }
    public static void main(String[] args) throws IOException{
        FastScanner scanner = new FastScanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        (new Solver()).solve(scanner, out);
        out.flush();

    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner(InputStream stream) {
            try {
                br = new BufferedReader(new InputStreamReader(stream));
            } catch(Exception e) {
                e.printStackTrace();
            }
        }

        boolean hasNextToken() {
            if(st == null) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch(IOException e) {

                }
            }
            return st.hasMoreTokens();
        }

        String next() {
            while(st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch(IOException e) {
                    e.printStackTrace();
                }
            }

            return st.nextToken();
        }

        String nextLine() throws IOException{
            return br.readLine();
        }

        byte nextByte() {
            return Byte.parseByte(next());
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}


import java.util.*;
import java.math.*;
import java.io.*;
import java.util.Collections;

public class Solution {

    static class Solver {

        Solver() {
        }

        public void solve(FastScanner sc, PrintWriter out) throws IOException {
            char[] arr = sc.nextLine().toCharArray();
            int n = arr.length;
            int ans = 0;
            for(int i = 0; i < n; i++) {
                int min = 0;
                int max = 0;
                for(int j = i; j < n; j++) {
                    if(arr[j] == '(') {
                        ++min;
                        ++max;
                    } else if(arr[j] == ')') {
                        if(max == 0) {
                            break;
                        }
                        --min;
                        --max;
                    } else {
                        --min;
                        ++max;
                    }

                    if(min == -1) {
                        min = 1;
                    }

                    if(min == 0) ++ans;
                }
            }
            out.println(ans);
        }
    }
    public static void main(String[] args) throws IOException{
        FastScanner scanner = new FastScanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        (new Solver()).solve(scanner, out);
        out.flush();

    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner(InputStream stream) {
            try {
                br = new BufferedReader(new InputStreamReader(stream));
            } catch(Exception e) {
                e.printStackTrace();
            }
        }

        boolean hasNextToken() {
            if(st == null) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch(IOException e) {

                }
            }
            return st.hasMoreTokens();
        }

        String next() {
            while(st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch(IOException e) {
                    e.printStackTrace();
                }
            }

            return st.nextToken();
        }

        String nextLine() throws IOException{
            return br.readLine();
        }

        byte nextByte() {
            return Byte.parseByte(next());
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            String s = in.next();
            int ans = 0;
            for (int i = 0; i < s.length(); i++) {
                int score = 0;
                int qmarks = 0;
                for (int j = i; j < s.length(); j++) {
                    if (s.charAt(j) == '(') score++;
                    else if (s.charAt(j) == ')') score--;
                    else if (s.charAt(j) == '?') qmarks++;

                    if (score < 0) {
                        break;
                    }
                    if (qmarks > score) {
                        score++;
                        qmarks--;
                    }
                    if ((j - i + 1) % 2 == 0 && qmarks == score) {
                        ans++;
                    }
                }
            }
            out.println(ans);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void println(int i) {
            writer.println(i);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                if (Character.isValidCodePoint(c)) {
                    res.appendCodePoint(c);
                }
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.LinkedList;

public class TheMonsterC459 {
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		String s=in.readLine();
		char[] chars=new char[s.length()];
		for(int i=0;i<s.length();i++)
			chars[i]=s.charAt(i);

		int tot=0,l,r;
		for(int i=0;i<chars.length;i++) {
			l=0;r=0;
			for(int j=0;j<chars.length;j++) {
				if(chars[j]==')') {
					l--;
					r--;
				}
				else if(chars[j]=='(') {
					l++;
					r++;
				}
				else {
					l--;
					r++;
				}
				if(r<0)break;
				if(l<0)l+=2;
				if(l==0)l++;
			}
		}
		out.println(tot);
		in.close();
		out.close();
	}
}


#include <stdio.h>
#include <vector>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

const int base = 10000;

typedef vector<int> LNUM;

void ADD(LNUM & A,LNUM & B)
{
	while (A.size() < B.size())
		A.push_back(0);
	while (B.size() < A.size())
		B.push_back(0);
	int temp = 0;
	int i;
	for(i = 0; i < A.size() && i < B.size(); ++i)
	{
		A[i] += (B[i] + temp);
		temp = A[i] / base;
		A[i] %= base;
	}
	if (temp) A.push_back(temp);
}

void SHL(LNUM & A, int k)
{
	for(int i = 0; i < k; ++i)
	{
		int temp = 0;
		for(int j = 0; j < A.size(); ++j)
		{
			A[j] *= 2;
			A[j] += temp;
			temp = A[j] / base;
			A[j] %= base;
		}
		if (temp) A.push_back(temp);
	}
}

void Print(const LNUM & A)
{
	printf("%d", A.back());
	for(int i = A.size() - 2; i >= 0; --i)
		printf("%04d", A[i]);
}

const int inf = 1000 * 1000 * 1000;

int n;

vector<int> V;
vector<bool> T;

vector<int> S;
map<int, int> M;

int main()
{
	scanf("%d", &n);
	char c[10];
	V.resize(n);
	T.resize(n);
	for(int i = 0; i < n; ++i)
	{
		scanf("%*c%s", &c);
		scanf("%d", &V[i]);
		T[i] = c[0] == 's';
		if (T[i])
		{
			S.push_back(V[i]);
			M[V[i]] = i;
		}
	}
	LNUM ANS(1, 0);
	sort(S.begin(), S.end());
	while (!S.empty())
	{
		int k = S.back();
		S.pop_back();
		for(int i = M[k]; i >= 0; --i)
		{
			if (V[i] == inf)
				break;
			if (!T[i] && V[i] == k)
			{
				for(int j = M[k]; j >= i; --j)
					V[j] = inf;
				LNUM temp(1, 1);
				SHL(temp, k);
				ADD(ANS, temp);
				break;
			}
		}
	}
	Print(ANS);
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define ll unsigned long long int
const ll w=1e18;
int nm(string p)
{
    int q(0);
    for (int i=0;i<p.size();i++) q=q*10+p[i]-'0';
    return q;
}
string st(ll p)
{
    string q("000000000000000000");
    for (int i=0;p>0;i++)
    {
        q[17-i]='0'+p%10;
        p/=10;
    }
    return q;
}
int n;
vector <string> s,t;
vector <int> u;
vector <int> a(2001,0),d(2001,0);
vector <int> b(0);
int x(-1),y;
vector <ll> c(1,1);
vector <ll> p2(vector <ll> p)
{
    p.push_back(0);
    ll q(0),r;
    for (int i=0;i<p.size();i++)
    {
        r=q;
        q=(p[i]*2+r)/w;
        p[i]=(p[i]*2+r)%w;
    }
    if (p[p.size()-1]==0) p.pop_back();
    return p;
}
vector <ll> s1(vector <ll> p)
{
    p.push_back(0);
    ll q(1),r;
    for (int i=0;i<p.size();i++)
    {
        r=q;
        q=(p[i]+r)/w;
        p[i]=(p[i]+r)%w;
    }
    if (p[p.size()-1]==0) p.pop_back();
    return p;
}
int main()
{
    cin >> n;
    s.resize(n);
    t.resize(n);
    u.resize(n);
    for (int i=0;i<n;i++)
    {
        cin >> s[i] >> t[i];
        u[i]=nm(t[i]);
        if (s[i]=="win") a[u[i]]++;
    }
    for (int i=n-1;i>=0;i--)
    {
        if (s[i]=="sell")
        {
            if (a[u[i]]>0) x=max(x,u[i]);
        }
        else
        {
            a[u[i]]--;
            if (u[i]==x)
            {
                b.push_back(x);
                d[x]=1;
                x=-1;
            }
        }
    }
    if (b.size()==0) cout << 0;
    else
    {
        y=*max_element(b.begin(),b.end());
        for (int i=y-1;i>=0;i--)
        {
            c=p2(c);
            if (d[i]==1) c=s1(c);
        }
        cout << c[c.size()-1];
        for (int i=c.size()-2;i>=0;i--) cout << st(c[i]);
    }
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define ll unsigned long long int
const ll w=1e18;
int nm(string p)
{
    int q(0);
    for (int i=0;i<p.size();i++) q=q*10+p[i]-'0';
    return q;
}
string st(ll p)
{
    string q("000000000000000000");
    for (int i=0;p>0;i++)
    {
        q[17-i]='0'+p%10;
        p/=10;
    }
    return q;
}
int n;
vector <string> s,t;
vector <int> u;
vector <int> a(2001,0),d(2001,0);
vector <int> b(0);
int x(-1),y;
vector <ll> c(1,1);
vector <ll> p2(vector <ll> p)
{
    p.push_back(0);
    ll q(0),r;
    for (int i=0;i<p.size();i++)
    {
        r=q;
        q=(p[i]*2+r)/w;
        p[i]=(p[i]*2+r)%w;
    }
    if (p[p.size()-1]==0) p.pop_back();
    return p;
}
vector <ll> s1(vector <ll> p)
{
    p.push_back(0);
    ll q(1),r;
    for (int i=0;i<p.size();i++)
    {
        r=q;
        q=(p[i]+r)/w;
        p[i]=(p[i]+r)%w;
    }
    if (p[p.size()-1]==0) p.pop_back();
    return p;
}
int main()
{
    cin >> n;
    s.resize(n);
    t.resize(n);
    u.resize(n);
    for (int i=0;i<n;i++)
    {
        cin >> s[i] >> t[i];
        u[i]=nm(t[i]);
        if (s[i]=="win") a[u[i]]++;
    }
    for (int i=n-1;i>=0;i--)
    {
        if (s[i]=="sell")
        {
            if (a[u[i]]>0) x=max(x,u[i]);
        }
        else
        {
            a[u[i]]--;
            if (u[i]==x)
            {
                b.push_back(x);
                d[x]++;
                x=-1;
            }
        }
    }
    if (b.size()==0) cout << 0;
    else
    {
        y=*max_element(b.begin(),b.end());
        for (int i=y-1;i>=0;i--)
        {
            c=p2(c);
            if (d[i]) c=s1(c);
        }
        cout << c[c.size()-1];
        for (int i=c.size()-2;i>=0;i--) cout << st(c[i]);
    }
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define ll unsigned long long int
const ll w=1e18;
int nm(string p)
{
    int q(0);
    for (int i=0;i<p.size();i++) q=q*10+p[i]-'0';
    return q;
}
string st(ll p)
{
    string q("000000000000000000");
    for (int i=0;p>0;i++)
    {
        q[17-i]='0'+p%10;
        p/=10;
    }
    return q;
}
int n;
vector <string> s,t;
vector <int> u;
vector <int> a(2001,0),d(2001,0);
vector <int> b(0);
int x(-1),y;
vector <ll> c(1,1);
vector <ll> p2(vector <ll> p)
{
    p.push_back(0);
    int q(0),r;
    for (int i=0;i<p.size();i++)
    {
        r=q;
        q=(2*p[i]+r)/w;
        p[i]=(2*p[i]+r)%w;
    }
    if (p[p.size()-1]==0) p.pop_back();
    return p;
}
vector <ll> s1(vector <ll> p)
{
    p.push_back(0);
    int q(1),r;
    for (int i=0;i<p.size();i++)
    {
        r=q;
        q=(p[i]+r)/w;
        p[i]=(p[i]+r)%w;
    }
    if (p[p.size()-1]==0) p.pop_back();
    return p;
}
int main()
{
    cin >> n;
    s.resize(n);
    t.resize(n);
    u.resize(n);
    for (int i=0;i<n;i++)
    {
        cin >> s[i] >> t[i];
        u[i]=nm(t[i]);
        if (s[i]=="win") a[u[i]]++;
    }
    for (int i=n-1;i>=0;i--)
    {
        if (s[i]=="sell")
        {
            if (a[u[i]]>0) x=max(x,u[i]);
        }
        else
        {
            a[u[i]]--;
            if (u[i]==x)
            {
                b.push_back(x);
                d[x]++;
                x=-1;
            }
        }
    }
    if (b.size()==0) cout << 0;
    else
    {
        y=*max_element(b.begin(),b.end());
        for (int i=y-1;i>=0;i--)
        {
            c=p2(c);
            if (d[i]) c=s1(c);
        }
        cout << c[c.size()-1];
        for (int i=c.size()-2;i>=0;i--) cout << st(c[i]);
    }
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define ll unsigned long long int
const ll w=1e18;
int nm(string p)
{
    int q(0);
    for (int i=0;i<p.size();i++) q=q*10+p[i]-'0';
    return q;
}
string st(ll p)
{
    string q("000000000000000000");
    for (int i=0;p>0;i++)
    {
        q[17-i]='0'+p%10;
        p/=10;
    }
    return q;
}
int n;
vector <string> s,t;
vector <int> u;
vector <int> a(2001,0),d(2001,0);
vector <int> b(0);
int x(-1),y;
vector <ll> c(1,1);
vector <ll> p2(vector <ll> p)
{
    p.push_back(0);
    int q(0),r;
    for (int i=0;i<p.size();i++)
    {
        r=q;
        q=(2*p[i]+r)/w;
        p[i]=(2*p[i]+r)%w;
    }
    if (p[p.size()-1]==0) p.pop_back();
    return p;
}
vector <ll> s1(vector <ll> p)
{
    p.push_back(0);
    int q(1),r;
    for (int i=0;i<p.size();i++)
    {
        r=q;
        q=(p[i]+r)/w;
        p[i]=(p[i]+r)%w;
    }
    if (p[p.size()-1]==0) p.pop_back();
    return p;
}
int main()
{
    cin >> n;
    s.resize(n);
    t.resize(n);
    u.resize(n);
    for (int i=0;i<n;i++)
    {
        cin >> s[i] >> t[i];
        u[i]=nm(t[i]);
        if (s[i]=="win") a[u[i]]++;
    }
    for (int i=n-1;i>=0;i--)
    {
        if (s[i]=="sell")
        {
            if (a[u[i]]>0) x=max(x,u[i]);
        }
        else if (u[i]==x)
        {
            b.push_back(x);
            d[x]++;
            x=-1;
        }
    }
    if (b.size()==0) cout << 0;
    else
    {
        y=*max_element(b.begin(),b.end());
        for (int i=y-1;i>=0;i--)
        {
            c=p2(c);
            if (d[i]) c=s1(c);
        }
        cout << c[c.size()-1];
        for (int i=c.size()-2;i>=0;i--) cout << st(c[i]);
    }
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define ll unsigned long long int
const ll w=1e18;
int nm(string p)
{
    int q(0);
    for (int i=0;i<p.size();i++) q=q*10+p[i]-'0';
    return q;
}
string st(ll p)
{
    string q("000000000000000000");
    for (int i=0;p>0;i++)
    {
        q[17-i]='0'+p%10;
        p/=10;
    }
    return q;
}
int n;
vector <string> s,t;
vector <int> u;
vector <int> d(2001,0);
vector <bool> f;
vector <int> b(0);
bool ff;
vector <ll> c(1,1);
vector <ll> p2(vector <ll> p)
{
    p.push_back(0);
    ll q(0),r;
    for (int i=0;i<p.size();i++)
    {
        r=q;
        q=(p[i]*2+r)/w;
        p[i]=(p[i]*2+r)%w;
    }
    if (p[p.size()-1]==0) p.pop_back();
    return p;
}
vector <ll> s1(vector <ll> p)
{
    p.push_back(0);
    ll q(1),r;
    for (int i=0;i<p.size();i++)
    {
        r=q;
        q=(p[i]+r)/w;
        p[i]=(p[i]+r)%w;
    }
    if (p[p.size()-1]==0) p.pop_back();
    return p;
}
int main()
{
    cin >> n;
    s.resize(n);
    t.resize(n);
    u.resize(n);
    f.assign(n,true);
    for (int i=0;i<n;i++)
    {
        cin >> s[i] >> t[i];
        u[i]=nm(t[i]);
    }
    for (int i=*max_element(u.begin(),u.end());i>=0;i--)
    {
        ff=true;
        for (int j=0;j<n && ff;j++) if (s[j]=="sell" && u[j]==i)
        {
            if (f[j])
            {
                for (int k=j-1;f[j] && k>=0 && f[k];k--) if (s[k]=="win" && u[k]==i)
                {
                    b.push_back(i);
                    d[i]++;
                    for (int l=k;l<=j;l++) f[l]=false;
                }
            }
            ff=false;
        }
    }
    if (b.size()==0) cout << 0;
    else
    {
        for (int i=b[0]-1;i>=0;i--)
        {
            c=p2(c);
            if (d[i]==1) c=s1(c);
        }
        cout << c[c.size()-1];
        for (int i=c.size()-2;i>=0;i--) cout << st(c[i]);
    }
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define ll unsigned long long int
const ll w=1e18;
int nm(string p)
{
    int q(0);
    for (int i=0;i<p.size();i++) q=q*10+p[i]-'0';
    return q;
}
string st(ll p)
{
    string q("000000000000000000");
    for (int i=0;p>0;i++)
    {
        q[17-i]='0'+p%10;
        p/=10;
    }
    return q;
}
int n;
vector <string> s,t;
vector <int> u;
vector <int> a(2001,0),d(2001,0);
vector <int> b(0);
int x(-1),y;
vector <ll> c(1,1);
vector <ll> p2(vector <ll> p)
{
    p.push_back(0);
    int q(0),r;
    for (int i=0;i<p.size();i++)
    {
        r=q;
        q=(2*p[i]+r)/w;
        p[i]=(2*p[i]+r)%w;
    }
    if (p[p.size()-1]==0) p.pop_back();
    return p;
}
vector <ll> s1(vector <ll> p)
{
    p.push_back(0);
    int q(1),r;
    for (int i=0;i<p.size();i++)
    {
        r=q;
        q=(p[i]+r)/w;
        p[i]=(p[i]+r)%w;
    }
    if (p[p.size()-1]==0) p.pop_back();
    return p;
}
int main()
{
    cin >> n;
    s.resize(n);
    t.resize(n);
    u.resize(n);
    for (int i=0;i<n;i++)
    {
        cin >> s[i] >> t[i];
        u[i]=nm(t[i]);
        if (s[i]=="win") a[u[i]]++;
    }
    for (int i=n-1;i>=0;i--)
    {
        if (s[i]=="sell")
        {
            if (a[u[i]]>0) x=max(x,u[i]);
        }
        else if (u[i]==x)
        {
            a[u[i]]--;
            b.push_back(x);
            d[x]++;
            x=-1;
        }
    }
    if (b.size()==0) cout << 0;
    else
    {
        y=*max_element(b.begin(),b.end());
        for (int i=y-1;i>=0;i--)
        {
            c=p2(c);
            if (d[i]) c=s1(c);
        }
        cout << c[c.size()-1];
        for (int i=c.size()-2;i>=0;i--) cout << st(c[i]);
    }
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define ll unsigned long long int
const ll w=1e18;
int nm(string p)
{
    int q(0);
    for (int i=0;i<p.size();i++) q=q*10+p[i]-'0';
    return q;
}
string st(ll p)
{
    string q("000000000000000000");
    for (int i=0;p>0;i++)
    {
        q[17-i]='0'+p%10;
        p/=10;
    }
    return q;
}
int n;
vector <string> s,t;
vector <int> u;
vector <int> d(2001,0);
vector <bool> f;
vector <int> b(0);
bool ff;
vector <ll> c(1,1);
vector <ll> p2(vector <ll> p)
{
    p.push_back(0);
    ll q(0),r;
    for (int i=0;i<p.size();i++)
    {
        r=q;
        q=(p[i]*2+r)/w;
        p[i]=(p[i]*2+r)%w;
    }
    if (p[p.size()-1]==0) p.pop_back();
    return p;
}
vector <ll> s1(vector <ll> p)
{
    p.push_back(0);
    ll q(1),r;
    for (int i=0;i<p.size();i++)
    {
        r=q;
        q=(p[i]+r)/w;
        p[i]=(p[i]+r)%w;
    }
    if (p[p.size()-1]==0) p.pop_back();
    return p;
}
int main()
{
    cin >> n;
    s.resize(n);
    t.resize(n);
    u.resize(n);
    f.assign(n,true);
    for (int i=0;i<n;i++)
    {
        cin >> s[i] >> t[i];
        u[i]=nm(t[i]);
    }
    for (int i=*max_element(u.begin(),u.end());i>=0;i--)
    {
        ff=true;
        for (int j=0;j<n && ff;j++) if (s[j]=="sell" && u[j]==i)
        {
            if (f[j])
            {
                for (int k=j-1;k>=0 && f[k];k--) if (s[k]=="win" && u[k]==i)
                {
                    b.push_back(i);
                    d[i]++;
                    for (int l=k;l<=j;l++) f[l]=false;
                }
            }
            ff=false;
        }
    }
    if (b.size()==0) cout << 0;
    else
    {
        for (int i=b[0]-1;i>=0;i--)
        {
            c=p2(c);
            if (d[i]==1) c=s1(c);
        }
        cout << c[c.size()-1];
        for (int i=c.size()-2;i>=0;i--) cout << st(c[i]);
    }
    return 0;
}