n=int(input())
script=input().split()
l=set()
for i in script:
  k=list("".join(set(i)))
  k.sort()
  k=str(k)
  l.add(k)
print(len(l))


n=int(input())
l=list(map(str,input().split()))
l1=[]
for i in l:
    lp=list(set(i))
    lp.sort()
    sp=str(lp)
    l1.append(sp)
s=set(l1)
#print(l1, s)
print(len(s))


n=int(input())
l=list(map(str,input().split()))
l1=[]
for i in l:
    lp=str(set(i))
    l1.append(lp)
s=set(l1)
print(len(s))


t=int(input())
l=list(input().split())
a=set()
for j in range(t):
    x=''.join(list(set(list(l[j]))))
    a.add(x)
print(len(a))


t=int(input())
l=list(input().split())
a=set()
for j in range(t):
    y=list(set(list(l[j])))
    y.sort()
    x=''.join(y)
    a.add(x)
print(len(a))


n = int(input())
s = {''.join(set(s)) for s in input().split()}
print(len(s))


n = int(input())
s = {''.join(sorted(set(s))) for s in input().split()}
print(len(s))


input()
a=list(input().split())
d={}
for s in a:
    b=sorted(set(s))
    d[str(b)]=1
print(d)
print(len(d))


input()
a=list(input().split())
d={}
for s in a:
    b=sorted(set(s))
    d[str(b)]=1
print(len(d))


input()
a=list(input().split())
c=set()
for s in a:
    b=set(s)
    c.add(str(b))
print(len(c))


input()
a=list(input().split())
c=set()
for s in a:
    b=set(s)
    c.add(str(b))
print(c)
print(len(c))


n = int(input())
a = input().split()
s1 = ""
s2 = ""
count = 0
for i in range(n):
    for j in range(len(a[i])):
        if a[i][j] not in s1:
            s1 += a[i][j]
    if s1 != s2:
        count += 1
    s2 = s1
print(count)


n = int(input())
a = input().split()
s1 = []
s2 = []
count = 0
for i in range(n):
    for j in range(len(a[i])):
        if a[i][j] not in s1:
            s1.append(a[i][j])
    k = sorted(s1)
    if k not in s2:
        count += 1
    s2.append(k)
    s1 = []
    k = []
print(count)


n = int(input())
arr = map(str, input().split())
d = {}

for ele in arr:
    a = set(ele)
    s = sorted(a)

    k = ""
    for item in s:
        k += item

    d[k] = d.get(k, 0)+1

print(len(d))


n = int(input())
arr = map(str, input().strip().split())
d = {}

for ele in arr:
    s = set(ele)
    k = ""
    for item in s:
        k += item
    k.join(sorted(k))

    if k in d:
        d[k] += 1
    else:
        d[k] = 1

print(len(d))


n = int(input())
arr = map(str, input().strip().split())
d = {}

for ele in arr:
    s = set(ele)
    k = ""
    for item in s:
        k += item
    k = "".join(sorted(k))

    if k in d:
        d[k] += 1
    else:
        d[k] = 1

print(len(d))


n = int(input())
arr = map(str, input().split())
d = {}

for ele in arr:
    s = set(ele)
    k = ""
    for item in s:
        k += item
    k = "".join(sorted(k))

    if k in d:
        d[k] += 1
    else:
        d[k] = 1

print(len(d))


n = int(input())
arr = map(str, input().split())
d = {}

for ele in arr:
    s = set(ele)
    k = ""
    for item in s:
        k += item
    k.join(sorted(k))

    if k in d:
        d[k] += 1
    else:
        d[k] = 1

print(len(d))


n = int(input())
l = input().split()
s = []
for i in l:
	t = list(set(i))
	t.sort()
	s.append("".join(t))
print(len(set(s)))


n = int(input())
l = input().split()
s = []
for i in l:
	t = set(list(i))
	s.append("".join(list(t)))
print(len(set(s)))


n = input()
s = input().split()
a = set()
for i in s:
    b = set()
    for j in i:
        b.add(j)
    a.add("".join(sorted(list(b))))
print (len(a))


n = input()
s = input().split()
a = set()
for i in s:
    b = set()
    for j in i:
        b.add(j)
    a.add(b)
print (len(a))


input()
print(len(set([str(set(w)) for w in input().split()])))


input()
a = []
for s in input().split():
    a.append(''.join(sorted(list(set(s)))))
print(len(set(a)))


class AramicWord(object):
    def __init__(self, word):
        self._word = word
        self._root = set(word)

    def get_root(self):
        return ''.join(sorted(set(self._root)))

    def get_word(self):
        return self._word

def AramicScript():
    n = int(input().strip())
    words = input().strip().split()

    for i in range(n):
        words[i] = (AramicWord(words[i]).get_root())

    return len(set(words))

if __name__ == '__main__':
    a = AramicScript()
    print(a)


class AramicWord(object):
    def __init__(self, word):
        self._word = word
        self._root = set(word)

    def get_root(self):
        return self._root

    def get_word(self):
        return self._word

def AramicScript():
    n = int(input().strip())
    words = input().strip().split()
    words = [''.join(AramicWord(word).get_root()) for word in words]
    return len(set(words))

if __name__ == '__main__':
    a = AramicScript()
    print(a)


n=input()
s=list(map(str,input().split()))
l=[]
for i in s:
    l.append(frozenset(set(i)))
print(len(set(l)))


n=input()
s=list(map(str,input().split()))
l=[]
for i in s:
    l.append(tuple(set(i)))
print(len(set(l)))


n=int(input())
s=input().split()
for i in range(n):
    s[i]=str(sorted(set(s[i])))
print(len(set(s)))


n=int(input())
s=input().split()
for i in range(n):
    s[i]=str(set(s[i]))
print(len(set(s)))


n = input();
array = list();
array = input().split();
index = [0]*26;
#index[] = new int[26];
count = 0;
arr = list();
for i in range(len(array)):
    word = array[i];
    str = "";
    for j in range(len(word)):
        index[ord(word[j])-97]+=1;

    #print (index)
    for j in range(26):
        if (index[j]!=0):
            str = str + chr(j+97);
    index = [0]*26;
    if (str not in arr):
        arr.append(str);
        count+=1;
    #print (arr)
print (count);


n = input();
array = list();
array = input().split();
index = [0]*26;
#index[] = new int[26];
count = 0;
for i in range(len(array)):
    word = array[i];
    for j in range(len(word)):
        #print (ord(word[j])-97);
        if (index[ord(word[j])-97]!=1):
            index[ord(word[j])-97] = 1;
            flag = 1;

    if (flag == 1):
        count+=1;
        flag = 0;
print (count);


n = int(input())
a = list(map(input().split()))
for i in range(n):
    a[i] = sorted(a[i])
s = set()
for i in range(n):
    s.add(a[i])
print(len(s))


n = int(input())
a = list(map(str, input().split()))
for i in range(n):
    q = set()
    for j in range(len(a[i])):
        q.add(a[i][j])
    q = list(q)
    q.sort()
    a[i] = q
s = set()
for i in range(n):
    s.add("".join(a[i]))
print(len(s))


n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    a[i] = sorted(a[i])
s = set()
for i in range(n):
    s.add(a[i])
print(len(s))


input()
s = input().split()
d = []
r = 0
for x in s:
    t = set(x)
    if t not in d:
        d.append(t)
        r += 1
print(r)


n = int(input())
s = set()

a = input().split()

for j in a:
    f = ['0']*26
    for l in j:
        f[ord(l)-97] = '1'
    st = ''.join(f)
    s.add(st)
print(len(s))


n = int(input())
s = set()

a = input().split()
for j in a:
    f = set()
    for l in j:
        f.update(l)
    print(f)
    s.update(f)

print(len(s))


def manuscript(lst):
    w = set()
    for elem in lst:
        w.add(''.join(sorted(set(elem))))
    return len(w)

words = input().strip().split()
print(manuscript(words))


def manuscript(lst):
    w = set()
    for elem in lst:
        w.add(''.join(sorted(set(elem))))
    return len(w)

n = int(input())
words = input().strip().split()
print(manuscript(words))


#Zadacha D
n=int(input())
words=list(map(list,input().split()))
korni=[]
words.sort()
i=0
while i<=len(words)-1:
    if i<len(words)-1:
        if words[i]==words[i+1]:
            words.pop(i+1)
            continue

    words[i].sort()
    k=0
    while k<len(words[i])-1:
        if words[i][k]==words[i][k+1]:
            words[i].pop(k+1)
        else:k+=1
    korni.append(words[i])
    i+=1

k=0
while k<len(korni)-1:
    if korni[k]==korni[k+1]:
        korni.pop(k+1)
    else:k+=1
print(len(korni))


#Zadacha D
n=int(input())
words=list(map(list,input().split()))
korni=[]
words.sort()
i=0
while i<=len(words)-1:
    if i<len(words)-1:
        if words[i]==words[i+1]:
            words.pop(i+1)
            continue

    words[i].sort()
    k=0
    while k<len(words[i])-1:
        if words[i][k]==words[i][k+1]:
            words[i].pop(k+1)
        else:k+=1
    korni.append(words[i])
    i+=1
korni.sort()
k=0
while k<len(korni)-1:
    if korni[k]==korni[k+1]:
        korni.pop(k+1)
    else:k+=1
print(len(korni))


#Zadacha D
n=int(input())
words=list(map(list,input().split()))
korni=[]
words.sort()
i=0
while i<=len(words)-1:
    if i<len(words)-1:
        if words[i]==words[i+1]:
            words.pop(i+1)
            break
    words[i].sort()
    k=0
    while k<len(words[i])-1:
        if words[i][k]==words[i][k+1]:
            words[i].pop(k+1)
        else:k+=1
    korni.append(words[i])
    i+=1

k=0
while k<len(korni)-1:
    if korni[k]==korni[k+1]:
        korni.pop(k+1)
    else:k+=1
print(len(korni))


#Zadacha D
n=int(input())
words=list(map(list,input().split()))
korni=[]
for i in range(len(words)):
    words[i].sort()
    k=0
    while k<len(words[i])-1:
        if words[i][k]==words[i][k+1]:
            words[i].pop(k+1)
        else:k+=1
    korni.append(words[i])
korni.sort()
k=0
while k<len(korni)-1:
    if korni[k]==korni[k+1]:
        korni.pop(k+1)
    else:k+=1
print(len(korni))


n=input()
l=list(map(set,input().split()))
l=set(map(str,l))
print(len(l))


n=int(input())
l=list(map(set,input().split()))
l1=[]
l1.append(l[0])
for i in range(1,n):
    if l[i] in l1:
        pass
    else:
        l1.append(l[i])
print(len(l1))


n=int(input())
l=list(map(set,input().split()))
print(l)
l=set(map(str,l))
print(len(l))


n=int(input())
l=list(map(list,input().split()))
l=list(map(set,l))
l=set(list(map(str,l)))
print(len(l))


n=int(input())
l=list(map(set,input().split()))
l=set(map(str,l))
print(len(l))


n = int(input())
l = list(input().split())
li = [str(sorted(set(i))) for i in l]
print(len(set(li)))


n = int(input())
l = list(input().split())
li = [str(set(i)) for i in l]
print(len(set(li)))


n=int(input())
s=input().split()
dic={}
count=0
for i in range(0,n):
    dic[i]=[]
    count+=1
    flag=0
    for j in s[i]:
        if j in dic[i]:
            flag=1
        else:
            dic[i]+=[j]
    dic[i].sort()
    if flag==1:
        count-=1
        del(dic[i])
list=[]
for i in dic:
    if dic[i] in list:
        count=count-1
    else:
        list+=[dic[i]]
print(count)


n=int(input())
s=input().split()
dic={}
count=0
for i in range(0,n):
    dic[i]=[]
    count+=1
    flag=0
    for j in s[i]:
        if j in dic[i]:
            flag=1
        else:
            dic[i]+=[j]
    dic[i].sort()
list=[]
for i in dic:
    if dic[i] in list:
        count=count-1
    else:
        list+=[dic[i]]
print(count)


#include <iostream>
#include <string>
using namespace std;
int main()
{
    long l=0,n=0;
    char s;
    while(cin.get(s))
    {
        if(s=='(') l++;
        else if(s==')') l--;
        else break;
        if(l<0){l=0; n++;}
        //if(s=='1')break;
        n++;
    }
    cout<<n-l;
    cin>>l;
    return 0;
}


#include <iostream>
#include <string>
using namespace std;
int main()
{
    string s;
    cin>>s;
    long i,j,n=s.size();
    bool a=true;
    while(a){
        a=false;
        for(i=0;i<s.size()-1;i++)
        {
            if(s[i]=='('&&s[i+1]==')')
            {
                s=s.substr(0,i)+s.substr(i+2,s.size()-2);
                //cout<<s<<endl;
                a=true;
                break;
            }
        }
    }
    cout<<n-s.size();
    cin>>n;
    return 0;
}


#include <iostream>
#include <string>
using namespace std;
int main()
{
    long l=0,n=0;
    char s;
    while(cin.get(s))
    {
        if(s=='(') l++;
        if(s==')') l--;
        if(l<0)l=1;
        //if(s=='1')break;
        n++;
    }
    cout<<n-l-1;
    cin>>l;
    return 0;
}


#include <iostream>
#include <string>
using namespace std;
int main()
{
    long l=0,n=0;
    char s;
    while(cin.get(s))
    {
        if(s=='(') l++;
        else if(s==')') l--;
        else break;
        if(l<0){l=0; n--;}
        //if(s=='1')break;
        n++;
    }
    cout<<n-l;
    cin>>l;
    return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
    char a;
    int a1=0,a2=0;
    while(1)
    {
        scanf("%c",&a);
        if(a=='\n')
            break;
        if(a=='(')
            a1++;
        else
        if(a==')'&&a1>0)
        {
            a1--;
            a2++;
        }
    }
    printf("%d",a2*2);
    return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <memory.h>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdlib>

using namespace std;

typedef vector<int> vint;
typedef vector<vint> vvint;
typedef long long LL;

const int inf = 1000 * 1000 * 1000;

vint V;
stack<int> S;

char s[100100];
int n;

int main()
{
	gets(s);
	n = strlen(s);
	V.resize(n, -1);
	for(int i = 0; i < n; ++i)
	{
		if (s[i] == '(')
			S.push(i);
		else
		{
			if (S.size() > 0)
			{
				int t = S.top();
				S.pop();
				V[t] = i;
				V[i] = t;
			}
		}
	}
	int res = 0;
	for(int i = 0; i < n; ++i)
		if (V[i] != -1)
			res++;
	printf("%d", res);
	return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <memory.h>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdlib>

using namespace std;

typedef vector<int> vint;
typedef vector<vint> vvint;
typedef long long LL;

const int inf = 1000 * 1000 * 1000;

vint V;
stack<int> S;

char s[1000100];
int n;

int main()
{
        gets(s);
        n = strlen(s);
        V.resize(n, -1);
        for(int i = 0; i < n; ++i)
        {
                if (s[i] == '(')
                        S.push(i);
                else
                {
                        if (S.size() > 0)
                        {
                                int t = S.top();
                                S.pop();
                                V[t] = i;
                                V[i] = t;
                        }
                }
        }
        int res = 0;
        for(int i = 0; i < n; ++i)
                if (V[i] != -1)
                        res++;
        printf("%d", res);
        return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <memory.h>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdlib>

using namespace std;

typedef vector<int> vint;
typedef vector<vint> vvint;
typedef long long LL;

const int inf = 1000 * 1000 * 1000;

vint V;
stack<int> S;

char s[100100];
int n;

int main()
{
        gets(s);
        n = strlen(s);
        V.resize(n, -1);
        for(int i = 0; i < n; ++i)
        {
                if (s[i] == '(')
                        S.push(i);
                else
                {
                        if (S.size() > 0)
                        {
                                int t = S.top();
                                S.pop();
                                V[t] = i;
                                V[i] = t;
                        }
                }
        }
        int res = 0;
        for(int i = 0; i < n; ++i)
                if (V[i] != -1)
                        res++;
        printf("%d", res);
        return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include<cmath>
#include <stack>

using namespace std;

int main() {

	string brackets;

	cin >> brackets;

	//stack<int> openedBrackets;
	int openedBrackets = 0;

	for (int i = 0; i < brackets.length(); i++)
	{
		char value = brackets[i];
		if (value == '(') {
			//openedBrackets.push(i);
			openedBrackets++;
		}
		else {
			//if (!openedBrackets.empty()) {
			if (!(openedBrackets == 0)) {
				//openedBrackets.pop();
				openedBrackets--;
			}
			else {
				brackets.erase(i, 1);
				i--;
			}
		}
	}

	/*while (!openedBrackets.empty()) {
		brackets.erase(openedBrackets.top(), 1);
		openedBrackets.pop();
	}*/

	//cout << brackets.length() - openedBrackets.size();
	cout << brackets.length() - openedBrackets;
}


#include <iostream>
#include <algorithm>
#include <string>
#include<cmath>
#include <stack>

using namespace std;

int main() {

	string brackets;

	cin >> brackets;

	//stack<int> openedBrackets;
	int openedBrackets = 0;

	int stringLength = brackets.length();

	for (int i = 0; i < brackets.length(); i++)
	{
		char value = brackets[i];
		if (value == '(') {
			//openedBrackets.push(i);
			openedBrackets++;
		}
		else {
			//if (!openedBrackets.empty()) {
			if (!(openedBrackets == 0)) {
				//openedBrackets.pop();
				openedBrackets--;
			}
			else {
				//brackets.erase(i, 1);
				//i--;
				stringLength--;
			}
		}
	}

	/*while (!openedBrackets.empty()) {
		brackets.erase(openedBrackets.top(), 1);
		openedBrackets.pop();
	}*/

	//cout << brackets.length() - openedBrackets.size();
	cout << stringLength - openedBrackets;
}


#include <iostream>
#include <algorithm>
#include <string>
#include<cmath>
#include <stack>

using namespace std;

int main() {

	string brackets;

	cin >> brackets;

	stack<int> openedBrackets;

	for (int i = 0; i < brackets.length(); i++)
	{
		char value = brackets[i];
		if (value == '(') {
			openedBrackets.push(i);
		}
		else {
			if (!openedBrackets.empty()) {
				openedBrackets.pop();
			}
			else {
				brackets.erase(i, 1);
				i--;
			}
		}
	}

	/*while (!openedBrackets.empty()) {
		brackets.erase(openedBrackets.top(), 1);
		openedBrackets.pop();
	}*/

	cout << brackets.length() - openedBrackets.size();
}


#include <iostream>
#include <algorithm>
#include <string>
#include<cmath>
#include <stack>

using namespace std;

int main() {

	string brackets;

	cin >> brackets;

	stack<int> openedBrackets;

	for (int i = 0; i < brackets.length(); i++)
	{
		char value = brackets[i];
		if (value == '(') {
			openedBrackets.push(i);
		}
		else {
			if (!openedBrackets.empty()) {
				openedBrackets.pop();
			}
			else {
				brackets.erase(i, 1);
				i--;
			}
		}
	}

	while (!openedBrackets.empty()) {
		brackets.erase(openedBrackets.top(), 1);
		openedBrackets.pop();
	}

	cout << brackets.length();
}


#include <iostream>
#include <algorithm>
#include <string>
#include<cmath>
#include <stack>

using namespace std;

int main() {

	string brackets;

	cin >> brackets;

	//stack<int> openedBrackets;
	int openedBrackets = 0;

	for (int i = 0; i < brackets.length(); i++)
	{
		char value = brackets[i];
		if (value == '(') {
			//openedBrackets.push(i);
			openedBrackets++;
		}
		else {
			//if (!openedBrackets.empty()) {
			if (!(openedBrackets == 0)) {
				//openedBrackets.pop();
				openedBrackets--;
			}
			else {
				//brackets.erase(i, 1);
				//i--;
			}
		}
	}

	/*while (!openedBrackets.empty()) {
		brackets.erase(openedBrackets.top(), 1);
		openedBrackets.pop();
	}*/

	//cout << brackets.length() - openedBrackets.size();
	cout << brackets.length() - openedBrackets;
}


#include<iostream>
#include<stdio.h>
#include<sstream>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<fstream>
#include<ctype.h>
#include<iomanip>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
ll oo = 1e9;
ll nmod(ll a){ return (((a%oo) + oo) % oo); }
typedef pair<int, int> ii;

int main(){
//freopen("amer.in","r",stdin);
//freopen("amer.txt", "w",stdout);
string s;
getline(cin,s);
  int c=0;
  int y=0;
  for(int  i=0;i<(int) s.length();i++)
  {
      if(s[i]=='(')   c++;

      if( c>0 && s[i]==')'){
          c--;
          y++;
      }

  }
  cout<<y*2;
return 0;
}


#include<iostream>
    #include<String>
    #include<algorithm>
    #include<stack>
    #include<sstream>
    #include<map>
    #include<utility>
    #include<queue>
    #include<conio.h>
    #include<set>
    using namespace std;
    int main()
    {
    string s;
    int c=0;
    getline(cin,s);
    stack<char> st;
    for(int i=0;i<(int)s.length();i++)
    {
    if(st.size()==0)
    {
    st.push(s[i]);
    }
    else if(st.top()=='('&&s[i]==')')
    {
    st.pop();
    c++;
    }
    else
    {st.push(s[i]);}

    }
    cout<<c*2<<endl;

    return 0;
    }


#include<iostream>
#include<string>
using namespace std;
void main() {
	int count=0;
	int total=0;
	string s;
	cin >> s;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == '(')
			count++;
		else if (s[i] == ')' && count != 0) {
			count--;
			total = total + 2;
		}

	}
	cout << total;
}


#include<iostream>
#include<string>
using namespace std;

void main(){
    string s;
    int count1=0,count2=0;
    cin>>s;
    for(int i=0;i<s.length();i++){

        if(s[i]=='('){
            count1++;
        }

        else if(s[i]==')')
        count2++;

    }
    if(count1==count2){
    int f;
    f=count1+count2;
    cout<<f;
    }
    else if(count1>count2){
    int z= count1-count2;
    cout<<z;
    }

    else if(count2>count1){
    int x1=count2-count1;
    cout<<x1;
    }
}


#include<iostream>
#include<string>

using namespace std;

void main(){
    string s;
    int n,count1,count2;
    for(int i=0;i<s.length();i++){
        cin>>s;
        if(s[i]=="("){
            count1++;
        }

        else if(s[i]==")")
        count2++;

    }
    if(count1==count2){
    int f;
    f=count1+count2;
    cout<<f;
    }
    else if(count1>count2){
    int z= count1-count2
    cout<<z;
    }

    else if(count2>count1){
    int x1=count2-count1
    cout<<x1;
    }
}


#include<iostream>
#include<string>
#include<stack>
using namespace std;
void main() {
	stack<char> c1;
	int count = 0,total=0;
	string s;
	cin >> s;
	for (int i = 0; i < s.length(); i++) {
		c1.push(s[i]);
		if (c1.top() == '(')
			count++;
		else if (c1.top() == ')') {
			if (count != 0) {
				count--;
				total += 2;
			}
		}
	}
	cout << total;
}


#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<numeric>
#include<cmath>
#include<iomanip>
#include<sstream>
#include<bitset>
#include<stack>
#include<queue>
#include<list>
#include<stdio.h>
#include <cstdlib>
using namespace std;
int main()
{

    string s;
    cin >> s;
    int ans = 0;
    pair<char, int>p[1000000];
    stack<pair<char, int> >st;
    for (int i = 0; i < s.size(); i++)
        p[i].first = s[i], p[i].second = i;
    for (int i = 0; i < s.size(); i++)
    {
        if (st.size() != 0)
        {
            if (st.top().first == '('&& p[i].first == ')')
                ans++,st.pop();
            else
                st.push(p[i]);
        }
        else
            st.push(p[i]);
    }
    cout << ans*2 << endl;

    return 0;
}


#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<numeric>
#include<cmath>
#include<iomanip>
#include<sstream>
#include<bitset>
#include<stack>
#include<queue>
#include<list>
#include<stdio.h>
#include <cstdlib>
using namespace std;
int main()
{

    string s;
    cin >> s;
    vector<int>v(s.size(), 0);
    pair<char, int>p[1000];
    stack<pair<char, int> >st;
    for (int i = 0; i < s.size(); i++)
        p[i].first = s[i], p[i].second = i;
    for (int i = 0; i < s.size(); i++)
    {
        if (st.size() != 0)
        {
            if (st.top().first == '('&& p[i].first == ')')
            {
                v[st.top().second] = v[p[i].second] = -1;
                st.pop();
            }
            else
                st.push(p[i]);
        }
        else
            st.push(p[i]);
    }
    int ans = 0, mx = 0;
    v.push_back(0);
    for (int i = 0; i < v.size(); i++)
    {
        if (v[i] == -1)
            mx++;
        else
            ans = max(mx, ans), mx = 0;
    }
    cout << ans << endl;

    return 0;
}


#include <cstdio>
#include <cmath>
#include <string.h>

int open, len;
char s[1000005];

int main()
{
    open = len = 0;
    scanf("%s", s);
    for (int i = 0; i < strlen(s); ++i)
    {
        if (s[i] == '(')
        {
            ++open;
        }
        else
        {
            if (open > 0)
            {
                --open;
                len += 2;
            }
        }
    }

    printf("%d", len);

    return 0;
}


#include <cstdio>
#include <cmath>
#include <string.h>

int open, len;
char c;

int main()
{
    open = len = 0;
    while (scanf("%c", &c) == 1)
    {
        if (c == '(')
        {
            ++open;
        }
        else if (c ==')')
        {
            if (open > 0)
            {
                --open;
                len += 2;
            }
        }
    }

    printf("%d", len);

    return 0;
}


#include <cstdio>
#include <cmath>
#include <string.h>

int open, len;
char s[1000005];

int main()
{
    open = len = 0;
    gets(s);
    for (int i = 0; i < strlen(s); ++i)
    {
        if (s[i] == '(')
        {
            ++open;
        }
        else
        {
            if (open > 0)
            {
                --open;
                len += 2;
            }
        }
    }

    printf("%d", len);

    return 0;
}


#include <cstdio>
#include <cmath>

char c;
int open, len;

int main()
{
    //freopen("in.txt", "rt", stdin);
    open = len = 0;
    while (scanf("%c", &c) == 1)
    {
        if (c == '(')
        {
            ++open;
        }
        else
        {
            if (open > 0)
            {
                --open;
                len += 2;
            }
        }
    }

    printf("%d", len);

    return 0;
}


#include<iostream>
#inlcude<string>
using namespace std;
int main()
{
    string st;
   int i,s=0,k=0;
  cin>>st;
  for (i=0;i<st.size();i++)
     if (st[i]==40)
        {
           ++s;++k;
        }
       else
      if (k>0) {--k;++s;}
     cout<<s-k;
}


#include <iostream>
using namespace std;
int main()
{int c,k=0,s=0;
char c;
   while (getch(c))
   if (c=41)
       {
          ++k;
          ++s;
       }
   else
{
  if (k>0)
      {
         --k;
         ++s;
      }
}
   cout<<s-k;
}


#include <iostream>
using namespace std;
int main()
{int k=0,s=0;
char c;
   while ((c=getchar())>39)
   if (c=41)
       {
          ++k;
          ++s;
       }
   else
{
  if (k>0)
      {
         --k;
         ++s;
      }
}
   cout<<s-k;
}


#include <stdio.h>
using namespace std;
int main()
{int c,k=0,s=0;
char c
   while (getch(c))
   if (c=41)
       {
          ++k;
          ++s;
       }
   else
{
  if (k>0)
      {
         --k;
         ++s;
      }
}
   cout<<s-k;
}


#include<iostream>
#include<string>
using namespace std;
int main()
{
    string st;
   int i,s=0,k=0;
  cin>>st;
  for (i=0;i<st.size();i++)
     if (st[i]==40)
        {
           ++s;++k;
        }
       else
      if (k>0) {--k;++s;}
     cout<<s-k;
}


#include <iostream>
using namespace std;
int main()
{int k=0,s=0;
char c;
   while (getchar(c))
   if (c=41)
       {
          ++k;
          ++s;
       }
   else
{
  if (k>0)
      {
         --k;
         ++s;
      }
}
   cout<<s-k;
}


#include <iostream>
using namespace std;
int main()
{int k=0,s=0;
char c;
   while (getch(c))
   if (c=41)
       {
          ++k;
          ++s;
       }
   else
{
  if (k>0)
      {
         --k;
         ++s;
      }
}
   cout<<s-k;
}


#include <iostream>
using namespace std;
int main()
{int k=0,s=0;
char c;
   while ((c=getchar()))
   if (c=41)
       {
          ++k;
          ++s;
       }
   else
{
  if (k>0)
      {
         --k;
         ++s;
      }
}
   cout<<s-k;
}


#include <iostream>
using namespace std;

int main() {
	string r;
	cin >> r;
	int t = 0;
	int x = 0;
	for(int i = 0 ; i < r.length();i++){
		if(r.at(i) == '('){
			t++;
			x++;
		}
		if(r.at(i) == ')' && x > 0){
			x--;
		}
	}
	cout << ((t - x) * 2) << endl;
	return 0;
}


#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstring>
#include <cstdlib>
#include <cstdarg>
#include <utility>
#include <cctype>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <ctime>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>

using namespace std;

typedef long long LL;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef unsigned long long ULL;

short CC_;
#define sf scanf
#define pf printf
#define NL pf("\n");
#define PP getchar();
#define SS printf(">_<LOOOOOK@MEEEEEEEEEEEEEEE<<( %d )>>\n",++CC_);
#define DD(x_) cout<<">>>>( "<<++CC_<<" ) "<<#x_<<": "<<x_<<endl;
#define EXT(st_) cout<<"\n>>>Exicution Time: "<<(double)(clock()-st_)/CLOCKS_PER_SEC<<endl;

//constants
const int SZ= 1E6;
const int INF= (1<<29);
const double EPS= 1E-9;
const double PI= 2*acos(0.0);

//function templates
template <class T>void DA(T* x, int l){for(int i=0; i<l;i++)cout<<"["<<i<<"]>> "<<x[i]<<'\n';}
template <class T>inline void sary(T* st, T* nd){while(st<nd)cin>>*st++;/*sf("%d", st++);*/}
template <class T>void tobin(T n,char*bin){int pos= 1<<((int)log2(n));while(pos>=1){if((n & pos)==0)*bin='0';else*bin='1';pos>>=1;bin++;}*bin='\0';}
template <class T>int strOccur(string&s,T&tgt){int oc= 0, p= s.find(tgt);while(p != string::npos){p = s.find(tgt, p+1);oc++;}return oc;}
template <class T>inline T LCM(T x,T y){return((x*y)/__gcd(x,y));}
int bigMod(int b,int e,int m){if(e==0)return 1;if(!e&1){int temp=bigMod(b,e/2,m)%m;return(temp*temp)%m;}else return((b%m)*(bigMod(b,e-1,m))%m)%m;}
LL todec(char* bin){LL dec= 0;short i= 0, len= strlen(bin) -1;while(bin[i]){if(bin[i++]=='1'){dec += 1<<len;} len--;}return dec;}
inline LL POW(LL base, int exp){LL p= 1; while(exp-->0){p *= base;} return p;}
bool ispal(const string& str){int len= str.length();for(int i= 0; i<len/2; i++){if(str[i]==str[len-i-1]){}else return false;}return true;}
bool comp(const int& a,const int& b){return a>b;}

void solve(void)
{
    string str;
    cin>>str;
    int count = 0;
    stack<char> brack;

    for(int i= 0; str[i]; i++){
        if(str[i] == '(') brack.push('(');
        else{
            if(!brack.empty()){
                count++;
                brack.pop();
            }
        }
    }

    cout<< 2*count <<endl;

}

int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    solve();
//    cout<< (int) '{'<<endl;
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
char cont[1000000];
int main()
{
	int s=0;
	scanf("%s",cont);
	int res=0;
	int len=strlen(cont);
	for(int i=0;i<len;i++)
	{
		if(cont[i]=='(')s++;
		else if(s>0)s--,res+=2;
	}
	printf("%d",res);
	//system("PAUSE");
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
char cont[1000000];
int main()
{
	int s=0;
	scanf("%s",cont);
	int res=0;
	for(int i=0;i<strlen(cont);i++)
	{
		if(cont[i]=='(')s++;
		else if(s>0)s--,res+=2;
	}
	printf("%d",res);
	//system("PAUSE");
	return 0;
}


// 26b.cpp : �������̨Ӧ�ó������ڵ㡣
//

#include "stdio.h"
#include "stack"
using namespace std;

stack<int> bra;
char buf[1000000];
int main()
{
	int res=0;
	scanf("%s",buf);
	for(int i=0;i<strlen(buf);i++)
	{
		if(buf[i]=='(')bra.push(10);
		else if(!bra.empty())bra.pop(),res+=2;
	}
	printf("%d",res);
	return 0;
}


#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include<algorithm>
using namespace std;

int main(){
    string s;
    stack <char>ss;
    int count = 0;

    cin >> s;
    for (int i = 0; i < s.size(); i++)
    {
        if (ss.empty())
            ss.push(s[i]);
        else
        {
            if (ss.top() == '(' && s[i] == ')')
            {
                count += 2;
                ss.pop();
            }
            else
                ss.push(s[i]);
        }
    }

    cout << count << endl;
}


#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include<algorithm>
using namespace std;

int main(){
    string str;
    stack <char>ss;
    int count = 0;

    cin >> str;
    for (int i = 0; i < str.size(); i++)
    {
        if (ss.empty())
            ss.push(str[i]);
        else
        {
            if (ss.top() == '(' && str[i] == ')')
            {
                count += 2;
                ss.pop();
            }
            else
                ss.push(str[i]);
        }
    }

    cout << count << endl;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
using namespace std;
int main()
{
    string s;
    cin>>s;
    stack<int>st;
    int count1=0,max1=0,len=s.size();
    for (int i=0;i<len;i++)
    {
        if (s[i]==')'&&st.empty())count1=0;
        else
        {
           if (s[i]=='(')st.push(i);
           else
           {
               count1=+2;
               st.pop();
               max1=max(max1,count1);
           }
        }
    }
    cout<<max1;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
using namespace std;
int main()
{
    string s;
    cin>>s;
    stack<int>st;
    int count1=0,max1=0,len=s.size();
    for (int i=0;i<len;i++)
    {
        if (s[i]==')'&&st.empty());
        else
        {
           if (s[i]=='(')st.push(i);
           else
           {
               count1+=i-st.top();
               st.pop();
               max1=max(max1,count1);
           }
        }
    }
    cout<<max1;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
using namespace std;
int main()
{
        string s;
        cin>>s;
        stack<int>st;
        int count1=0,max1=0,len=s.size();
        for (int i=0;i<len;i++)
        {
                if (s[i]==')'&&st.empty())count1=0;
                else
                {
           if (s[i]=='(')st.push(i);
                   else
                   {
                           count1=i-st.top()+1;
                           st.pop();
                           max1=max(max1,count1);
                   }
                }
        }
        cout<<max1;
        return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
using namespace std;
int main()
{
        string s;
        cin>>s;
        stack<int>st;
        int count1=0,max1=0,len=s.size();
        for (int i=0;i<len;i++)
        {
                if (s[i]==')'&&st.empty());
                else
                {
           if (s[i]=='(')st.push(i);
                   else
                   {
                           count1+=2;
                           st.pop();
                           max1=max(max1,count1);
                   }
                }
        }
        cout<<max1;
        return 0;
}


#include <stdio.h>
#include <vector>
#include <list>
#include <set>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <queue>
#include <cmath>
#include <map>
#define EPS 1e-10
#pragma comment(linker, "/STACK:256000000")

using namespace std;

int main(){
        //freopen("circles.in","rt",stdin);
        //freopen("circles.out","wt",stdout);
        //freopen("input.txt","rt",stdin);
        //freopen("output.txt","wt",stdout);
        char s[1000013];
        cin.getline(s,1000013);
        int n=strlen(s);
        int ans=n,k=0;
        for (int i=0;i<n;i++){
                if (s[i]==')'){
                        k--;
                }
                else{
                        k++;
                }
                if (k<0){
                        ans--;
                        k++;
                }
        }
        ans-=k;
        cout<<ans;
        return 0;
        //cout.setf(ios::fixed);cout.precision(20);
}


#include <stdio.h>
#include <vector>
#include <list>
#include <set>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <queue>
#include <cmath>
#include <map>
#define EPS 1e-10
#pragma comment(linker, "/STACK:256000000")

using namespace std;

int main(){
	//freopen("circles.in","rt",stdin);
	//freopen("circles.out","wt",stdout);
	//freopen("input.txt","rt",stdin);
	//freopen("output.txt","wt",stdout);
	char s[1000013];
	cin.getline(s,1000013);
	int n=strlen(s);
	int ans=n,k=0;
	for (int i=0;i<n;i++){
		if (s[i]==')'){
			k--;
		}
		else{
			k++;
		}
		if (k<0){
			ans--;
			k++;
		}
	}
	ans-=k;
	cout<<ans;
	return 0;
	//cout.setf(ios::fixed);cout.precision(20);
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <cstring>
#include <math.h>
#include<cstdio>
#include<deque>
#include<sstream>

/* You got a dream, you gotta protect it.*/

#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define sz(v) ((int)v.size())
#define rep(i,m) for(int i=0;i<(int)(m);i++)
#define oo ((int) 1e9)
#define mp make_pair
#define pi 2 * acos(0);
#define eps 1e-6
using namespace std;

int dx[] = {0 ,  0 , 1 ,-1 , 1 , 1 , -1 , -1 } ;
int dy[] = {1 , -1 , 0 , 0 , 1 ,-1 ,  1 , -1 } ;

int geti(){
    int y = 0, s = 1;
    char c = getchar();
    while ( !isdigit(c) && c!='-' ) c = getchar();
    if ( c == '-' ) s = -1 , c = getchar();
    while ( isdigit(c) ) y = y * 10 + ( c - '0' ) , c = getchar();
    return s * y;
}
string s;
int a,b,c,res;
bool f;
int  main()
{
    //freopen("test.in" , "rt" , stdin);
    cin >> s ;
    c=0;res=0;a=0;b=0;
    f=false;
    for ( int i = 0 ; i < sz(s) ; i++) {
        if ( s[i] =='(' ) {
            if ( c ==1 )  {
                res+=(min(a,b) *2 ) ;
                a-=min(a,b);
                b=0;
            }
            a++ ;
            f=true;
            c=0;
        }
        else if(s[i] == ')' && f) {
            b++;
            c=1;
        }

    }
    if ( c == 1 ) {
        res+=(min(a,b) *2 ) ;
    }
    printf("%d\n",res);
    return 0 ;
}


    #include <iostream>
    #include <string>
    #include <vector>
    #include <algorithm>
    #include <queue>
    #include <map>
    #include <set>
    #include <utility>
    #include <stack>
    #include <cstring>
    #include <math.h>
    #include<cstdio>
    #include<deque>
    #include<sstream>

    /* You got a dream, you gotta protect it.*/

    #define pb push_back
    #define mem(a,b) memset(a,b,sizeof(a))
    #define sz(v) ((int)v.size())
    #define rep(i,m) for(int i=0;i<(int)(m);i++)
    #define oo ((int) 1e9)
    #define mp make_pair
    #define pi 2 * acos(0);
    #define eps 1e-6
    using namespace std;

    int dx[] = {0 ,  0 , 1 ,-1 , 1 , 1 , -1 , -1 } ;
    int dy[] = {1 , -1 , 0 , 0 , 1 ,-1 ,  1 , -1 } ;

    int geti(){
        int y = 0, s = 1;
        char c = getchar();
        while ( !isdigit(c) && c!='-' ) c = getchar();
        if ( c == '-' ) s = -1 , c = getchar();
        while ( isdigit(c) ) y = y * 10 + ( c - '0' ) , c = getchar();
        return s * y;
    }
    string s;
    int a,b,c,res;
    bool f;
    int  main()
    {
        //freopen("test.in" , "rt" , stdin);
        cin >> s ;
        c=0;res=0;a=0;b=0;
        f=false;
        for ( int i = 0 ; i < sz(s) ; i++) {
            if ( s[i] =='(' ) {
                if ( c ==1 )  {
                    res+=(min(a,b) *2 ) ;
                    a-=min(a,b);
                    b=0;
                }
                a++ ;
                f=true;
                c=0;
            }
            else if(s[i] == ')' && f) {
                b++;
                c=1;
            }

        }
        if ( c == 1 ) {
            res+=(min(a,b) *2 ) ;
        }
        printf("%d\n",res);
        return 0 ;
    }


#include<iostream>
#include<stack>
#include<string>
using namespace std;

void main(){
	string user;
	int count=0,total=0;
	stack<char> a;
	cin>>user;
	for(int i=user.size()-1;i>=0;i--){
		a.push(user[i]);
	}
	for(int i=0; i<user.size() ;i++){
		if(a.top()=='('){
			count++;
		}
		else
			if(count>0){
				count--;
				total+=2;
			}
		a.pop();
	}
	cout<<total<<endl;
}


int count=0,total=0;
	string user;
	stack<char> a;
	cin>>user;

	for(int i=user.length()-1 ; i>=0 ;i--)
		a.push(user[i]);

	for(int i=0 ; i<user.length() ;i++){
		if(a.top()=='(')
			count++;
		else if(count>0){
			count--;
			total+=2;
		}
		a.pop();
	}
	cout<<total<<endl;


#include<iostream>
#include<string>
using namespace std;

void main(){
	int count=0,total=0;
	string a;
	cin>>a;

	for(int i=0 ;i<a.length(); i++){
		if(a[i]=='(')
			count++;
		else if(count!=0){
			count--;
			total+=2;
			}
	}
	cout<<total<<endl;
}


#include <iostream>
#include <string>
#include <stack>
using namespace std;

void main ()
{
	int count=0,total=0;
	string user;
	stack<char> a;
	cin>>user;

	for(int i=user.length()-1 ; i>=0 ;i--)
		a.push(user[i]);

	for(int i=0 ; i<user.length() ;i++){
		if(a.top()=='(')
			count++;
		else if(count>0){
			count--;
			total+=2;
		}
		a.pop();
	}
	cout<<total<<endl;
}


#include<iostream>
#include<stack>
#include<string>
using namespace std;

void main(){
	string user;
	stack<char> a;
	cin>>user;
	int count=0,total=0;

	for(int i=0; i<user.length() ;i++){
		if(!a.empty() && a.top()=='(' && user[i]==')'){
			a.pop();
			total+=2;
		}
		else
			a.push(user[i]);
	}
	cout<<total<<endl;
}


#include <iostream>
#include <conio.h>

#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <complex>
#include <queue>
#include <utility>
#include <math.h>

using namespace std;

typedef int         I;
typedef long        s32;
typedef long long   s64;

int main()
{
    string  s       = 0;
    int     res, balance;

    cin>>s;
    int     length  = s.length();

    for (int i = 0; i < length; i++)
    {
        if (s[i] == '(')
            balance++;
        else
        {
            if (balance > 0)
            {
                res += 2;
                balance--;
            }
        }
    }

    cout<<res;

    return 0;
}


#include <iostream>
#include <conio.h>

#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <complex>
#include <queue>
#include <utility>
#include <math.h>

using namespace std;

typedef int         I;
typedef long        s32;
typedef long long   s64;

int main()
{
    string  s;
    int     res     = 0;
    int     balance = 0;

    cin>>s;
    int     length  = s.length();

    for (int i = 0; i < length; i++)
    {
        if (s[i] == '(')
            balance++;
        else
        {
            if (balance > 0)
            {
                res += 2;
                balance--;
            }
        }
    }

    cout<<res;

    return 0;
}


// 25-A.cpp : �R���\�[�� �A�v���P�[�V�����̃G���g�� �|�C���g���`���܂��B
//

#include "iostream"
#include <fstream>
#include "string"

using namespace std;

void main()
{
	string in;
	cin >> in;
//	string baff;

	int sum=0;
	int enemy = 0;

	for( int i=0; i<(int)in.size(); i++ ){
//		baff = in.substr(i,1);
		if( in[i] == '(' ){
			sum++;
		}
		if( in[i] == ')' ){
			if( sum <=0 ){
				enemy++;
			}
			sum--;
		}
	}

	cout << in.size() - abs( sum ) - 2*enemy<< endl;

	//int n;
	//cin >> n;
	//int baff;
	//int nokori;

	//int num=0;
	//int sum=0;

	//for( int i = 1; i<=n; i++ ){

	//	baff = i;
	//	nokori = i;

	//	num = 0;

	//	for( int j =2; j<baff; j++ ){

	//		if( nokori%j!=0 ){
	//			continue;
	//		}

	//		num++;

	//		if( num>2 ){
	//			break;
	//		}

	//		do{
	//			nokori = nokori / j;
	//		}while( nokori%j==0);

	//	}

	//	if( num == 2 ){
	//		sum++;
	//	}

	//}

	//cout << sum << endl;

}


#include "iostream"
#include <fstream>
#include "string"

using namespace std;

void main()
{
    string in;
    cin >> in;

    int sum=0;
    int enemy = 0;

    for( int i=0; i<(int)in.size(); i++ ){
        if( in[i] == '(' ){
            sum++;
        }
        if( in[i] == ')' ){
            if( sum > 0 ){  sum--;  }
            if( sum < 0 ){  enemy++;    }
//          if( sum <=0 ){
//              enemy++;
//          }
//          sum--;
        }
    }

//  if( sum < 0) enemy = enemy + sum;

    cout << in.size() - abs( sum ) - enemy << endl;
}


void main()
{
    string in;
    cin >> in;

    int sum=0;
    int enemy = 0;

    for( int i=0; i<(int)in.size(); i++ ){
        if( in[i] == '(' ){
            sum++;
        }
        if( in[i] == ')' ){
            if( sum > 0 ){  sum--;  }
            if( sum < 0 ){  enemy++;    }
//          if( sum <=0 ){
//              enemy++;
//          }
//          sum--;
        }
    }

//  if( sum < 0) enemy = enemy + sum;

    cout << in.size() - abs( sum ) - enemy << endl;
    }


// 25-A.cpp : �R���\�[�� �A�v���P�[�V�����̃G���g�� �|�C���g���`���܂��B
//

#include "iostream"
#include <fstream>
#include "string"

using namespace std;

void main()
{
	string in;
	cin >> in;

	int sum=0;
	int enemy = 0;

	for( int i=0; i<(int)in.size(); i++ ){
		if( in[i] == '(' ){
			sum++;
		}
		if( in[i] == ')' ){
			if( sum > 0 ){	sum--;	}
			else if( sum <= 0 ){	enemy++;}
//			if( sum <=0 ){
//				enemy++;
//			}
//			sum--;
		}
	}

//	if( sum < 0) enemy = enemy + sum;

	cout << in.size() - abs( sum ) - enemy << endl;

	//int n;
	//cin >> n;
	//int baff;
	//int nokori;

	//int num=0;
	//int sum=0;

	//for( int i = 1; i<=n; i++ ){

	//	baff = i;
	//	nokori = i;

	//	num = 0;

	//	for( int j =2; j<baff; j++ ){

	//		if( nokori%j!=0 ){
	//			continue;
	//		}

	//		num++;

	//		if( num>2 ){
	//			break;
	//		}

	//		do{
	//			nokori = nokori / j;
	//		}while( nokori%j==0);

	//	}

	//	if( num == 2 ){
	//		sum++;
	//	}

	//}

	//cout << sum << endl;

}


// 25-A.cpp : �R���\�[�� �A�v���P�[�V�����̃G���g�� �|�C���g���`���܂��B
//

#include "iostream"
#include <fstream>
#include "string"

using namespace std;

void main()
{
	string in;
	cin >> in;

	int sum=0;
	int enemy = 0;

	for( int i=0; i<(int)in.size(); i++ ){
		if( in[i] == '(' ){
			sum++;
		}
		if( in[i] == ')' ){
			if( sum > 0 ){	sum--;	}
			if( sum <= 0 ){	enemy++;}
//			if( sum <=0 ){
//				enemy++;
//			}
//			sum--;
		}
	}

//	if( sum < 0) enemy = enemy + sum;

	cout << in.size() - abs( sum ) - enemy << endl;

	//int n;
	//cin >> n;
	//int baff;
	//int nokori;

	//int num=0;
	//int sum=0;

	//for( int i = 1; i<=n; i++ ){

	//	baff = i;
	//	nokori = i;

	//	num = 0;

	//	for( int j =2; j<baff; j++ ){

	//		if( nokori%j!=0 ){
	//			continue;
	//		}

	//		num++;

	//		if( num>2 ){
	//			break;
	//		}

	//		do{
	//			nokori = nokori / j;
	//		}while( nokori%j==0);

	//	}

	//	if( num == 2 ){
	//		sum++;
	//	}

	//}

	//cout << sum << endl;

}


// 25-A.cpp : �R���\�[�� �A�v���P�[�V�����̃G���g�� �|�C���g���`���܂��B
//

#include "iostream"
#include <fstream>
#include "string"

using namespace std;

void main()
{
	string in;
	cin >> in;
//	string baff;

	int sum=0;

	for( int i=0; i<(int)in.size(); i++ ){
//		baff = in.substr(i,1);
		if( in[i] == '(' ){
			sum--;
		}
		if( in[i] == ')' ){
			sum++;
		}
	}

	cout << in.size() - abs( sum ) << endl;

	//int n;
	//cin >> n;
	//int baff;
	//int nokori;

	//int num=0;
	//int sum=0;

	//for( int i = 1; i<=n; i++ ){

	//	baff = i;
	//	nokori = i;

	//	num = 0;

	//	for( int j =2; j<baff; j++ ){

	//		if( nokori%j!=0 ){
	//			continue;
	//		}

	//		num++;

	//		if( num>2 ){
	//			break;
	//		}

	//		do{
	//			nokori = nokori / j;
	//		}while( nokori%j==0);

	//	}

	//	if( num == 2 ){
	//		sum++;
	//	}

	//}

	//cout << sum << endl;

}


#include "iostream"
#include <fstream>
#include "string"

using namespace std;

void main()
{
    string in;
    cin >> in;
//  string baff;

    int sum=0;
    int enemy = 0;

    for( int i=0; i<(int)in.size(); i++ ){
//      baff = in.substr(i,1);
        if( in[i] == '(' ){
            sum++;
        }
        if( in[i] == ')' ){
            if( sum <=0 ){
                enemy++;
            }
            sum--;
        }
    }

    if( sum < 0)enemy = enemy + sum;

    cout << in.size() - abs( sum ) - 2*enemy<< endl;
}


#include <iostream>
#include<string>
using namespace std;
void main(){
string str;
cin>>str;
if (str.length()%2!=0)
cout<<str.length()-1;
else
	cout<<str.length()-2;


#include <iostream>
#include<string>
#include<stack>
using namespace std;
void main(){
string str;
stack<char>q;
cin >>str;
int sum=0;
for(int i=0;i<str.length();i++){
	if (!q.empty()&&str[i]==')'&&q.top()=='(')
	{
		sum+=2;
	    q.pop();
	}
else
	q.push(str[i]);
}
cout<<sum;
}


#include <iostream>
#include<string>
using namespace std;
void main(){
string str;
cin>>str;
if (str.length()%2!=0)
cout<<str.length()-1;
else
	cout<<str.length()-2;
}


#include <iostream>
#include<string>
using namespace std;
void main(){
string str;
cin >>str;
int sum=0,count=str.length();
for(int i=0;i<str.length();i++){
if (str[i]=='(')
	sum++;
else if (str[i]==')'){
	sum--;
	if(sum<0){
      	count--;
        sum=0;
	}
}
}
cout<<count-sum;
}


#include<iostream>
#include<vector>
#include<fstream>
#include<queue>
#include<algorithm>
#include<list>
#include<cstdio>
#include<sstream>
#include<stack>
#include<cstring>
#include<cmath>
#include<string>
#include<map>
using namespace std;
#define     FOR(i,a,b)        for (int i=a; i<b; i++)
#define     Rep(i,a)          for (int i=0; i<a; i++)
#define     FIT(it,v)         for (typeof((v).begin())it=(v).begin(); it!=(v).end(); ++it)
#define     ALL(v)            (v).begin(),(v).end()
#define     Set(a,x)          memset((a),(x),sizeof(a))
#define     EXIST(a,b)        find(ALL(a),(b))!=(a).end()
#define     Sort(x)           sort(ALL(x))
#define     GSORT(x)          sort(ALL(x), greater<typeof(*((x).begin()))>())
#define     UNIQUE(v)         Sort(v); (v).resize(unique(ALL(v)) - (v).begin())
#define     MP                make_pair
#define     SZ(x)             (int)(x.size())
typedef long long ll;
typedef pair<int,int> pii;
int main(){
    //freopen("a.in","r",stdin);
    string s;
    cin >> s;
    stack<int>st;
    Rep(i,SZ(s))
    {
        if(s[i] == '(')
            st.push(s[i]);
        else if(s[i] == ')')
        {
            if(st.top() == '(')
                st.pop();
            else
                st.push(s[i]);
        }
    }
    cout << SZ(s)-SZ(st)<<endl;
    return 0;
}


#include<iostream>
#include<vector>
#include<fstream>
#include<queue>
#include<algorithm>
#include<list>
#include<cstdio>
#include<sstream>
#include<stack>
#include<cstring>
#include<cmath>
#include<string>
#include<map>
using namespace std;
#define     FOR(i,a,b)        for (int i=a; i<b; i++)
#define     Rep(i,a)          for (int i=0; i<a; i++)
#define     FIT(it,v)         for (typeof((v).begin())it=(v).begin(); it!=(v).end(); ++it)
#define     ALL(v)            (v).begin(),(v).end()
#define     Set(a,x)          memset((a),(x),sizeof(a))
#define     EXIST(a,b)        find(ALL(a),(b))!=(a).end()
#define     Sort(x)           sort(ALL(x))
#define     GSORT(x)          sort(ALL(x), greater<typeof(*((x).begin()))>())
#define     UNIQUE(v)         Sort(v); (v).resize(unique(ALL(v)) - (v).begin())
#define     MP                make_pair
#define     SZ(x)             (int)(x.size())
typedef long long ll;
typedef pair<int,int> pii;
int main(){
    //freopen("a.in","r",stdin);
    string s;
    cin >> s;
    stack<int>st;
    Rep(i,SZ(s))
    {
        if(s[i] == '(')
            st.push(s[i]);
        else if(s[i] == ')')
        {
            if(SZ(st) != 0 && st.top() == '(')
                st.pop();
            else
                st.push(s[i]);
        }
    }
    cout << SZ(s)-SZ(st)<<endl;
    return 0;
}


#include <iostream>
using namespace std;
void main()
{

int n;
int m ;
int sum;
sum=n+m;
}


#include <iodfdjbdjdb
dnfbdkjdnn
dbdfdgdg
nfsdd


include <iostream>
#include <string>
using namespace std;
void main()
{ string s;
cin>>s;
cout<<s;
}


#include <iostream>
#include <string>
using namespace std;
void main ()
{
    string s ;
    cin>>s;
}


fmngjfng
gnkfng
bkjgkdfh
nbfkjgjdf
fknfh
fhfnhfhf


#include <algorithm>

#include <iostream>

#include <fstream>

#include <sstream>

#include <cstring>

#include <cstdlib>

#include <cstdarg>

#include <utility>

#include <cctype>

#include <cstdio>

#include <vector>

#include <string>

#include <cmath>

#include <ctime>

#include <queue>

#include <deque>

#include <stack>

#include <set>

#include <map>

using namespace std;

typedef long long LL;

typedef vector<int> vint;

typedef pair<int,int> pint;

typedef unsigned long long ULL;

short CC_;

#define sf scanf

#define pf printf

#define NL pf("\n");

#define PP getchar();

#define SS printf(">_<LOOOOOK@MEEEEEEEEEEEEEEE<<( %d )>>\n",++CC_);

#define DD(x_) cout<<">>>>( "<<++CC_<<" ) "<<#x_<<": "<<x_<<endl;

#define EXT(st_) cout<<"\n>>>Exicution Time: "<<(double)(clock()-st_)/CLOCKS_PER_SEC<<endl;

//constants

const int SZ= 1E6;

const int INF= (1<<29);

const double EPS= 1E-9;

const double PI= 2*acos(0.0);

//function templates

template <class T>void DA(T* x, int l){for(int i=0; i<l;i++)cout<<"["<<i<<"]>> "<<x[i]<<'\n';}

template <class T>inline void sary(T* st, T* nd){while(st<nd)cin>>*st++;/*sf("%d", st++);*/}

template <class T>void tobin(T n,char*bin){int pos= 1<<((int)log2(n));while(pos>=1){if((n & pos)==0)*bin='0';else*bin='1';pos>>=1;bin++;}*bin='\0';}

template <class T>int strOccur(string&s,T&tgt){int oc= 0, p= s.find(tgt);while(p != string::npos){p = s.find(tgt, p+1);oc++;}return oc;}

template <class T>inline T LCM(T x,T y){return((x*y)/__gcd(x,y));}

int bigMod(int b,int e,int m){if(e==0)return 1;if(!e&1){int temp=bigMod(b,e/2,m)%m;return(temp*temp)%m;}else return((b%m)*(bigMod(b,e-1,m))%m)%m;}

LL todec(char* bin){LL dec= 0;short i= 0, len= strlen(bin) -1;while(bin[i]){if(bin[i++]=='1'){dec += 1<<len;} len--;}return dec;}

inline LL POW(LL base, int exp){LL p= 1; while(exp-->0){p *= base;} return p;}

bool ispal(const string& str){int len= str.length();for(int i= 0; i<len/2; i++){if(str[i]==str[len-i-1]){}else return false;}return true;}

bool comp(const int& a,const int& b){return a>b;}

void solve(void)

{

    string str;

    cin>>str;

    int count = 0;

    stack<char> brack;

    for(int i= 0; str[i]; i++){

        if(str[i] == '(') brack.push('(');

        else{

            if(!brack.empty()){

                count++;

                brack.pop();

            }

        }

    }

    cout<< 2*count <<endl;

}

int main(void)

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    solve();

//    cout<< (int) '{'<<endl;

    return 0;

}


fhkfjkhn
klkhnkfh
fnhfhtj
gjhu
gjhghjuk
mhghkjk
hjkkk


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <math.h>
#include <conio.h>
#include <utility>
#include <set>
#include <time.h>
#include <list>
#include <typeinfo>
#include <cstdio>
#include <numeric>
#include <limits>
#include <functional>
#include <stack>
using namespace std;
#define X first
#define Y second
#define PI 3.1415926535897932384626433832795
#define PI2 PI * 2
#define sqr(x) ((x)*(x))
#define all(n) (n).begin(), (n).end()
typedef long long LL;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef pair<double, double> pdd;
typedef vector<pdd> vpdd;
typedef pair<float, float> pff;
const int MOD = (int)1e9 + 7;
typedef double real;

void load(int k = 1) {
	if (k == 1)	{
#ifndef ONLINE_JUDGE
		freopen("in", "r", stdin);
		freopen("out", "w", stdout);
#endif
	} else if (k == 2) {
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	} else {
		freopen("in", "w", stdout);
	}
}

const int N = (int)1e5 + 1;
const int M = 3000;

void solve() {
	stack<char> s;
	int res = 0;
	string str;
	cin >> str;
	for (int i = 0; i < (int)str.size(); ++i) {
		if (str[i] == '(') {
			s.push(str[i]);
		} else {
			if (s.size()) {
				s.pop();
			} else {
				++res;
			}
		}
	}
	cout << str.size() - (res + s.size());
}

void solve2() {

}

#define TIME_CHECK

int main() {
#ifndef ONLINE_JUDGE
#ifdef TIME_CHECK
	double c1 = clock();
#endif
#endif

	load();
	solve();

#ifndef ONLINE_JUDGE
#ifdef TIME_CHECK
	double c2 = clock();
	cout << endl << "time: " << (c2 - c1) / (CLOCKS_PER_SEC / 1000);
#endif
#endif
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <math.h>
#include <conio.h>
#include <utility>
#include <set>
#include <time.h>
#include <list>
#include <typeinfo>
#include <cstdio>
#include <numeric>
#include <limits>
#include <functional>
#include <stack>
using namespace std;
#define X first
#define Y second
#define PI 3.1415926535897932384626433832795
#define PI2 PI * 2
#define sqr(x) ((x)*(x))
#define all(n) (n).begin(), (n).end()
typedef long long LL;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef pair<double, double> pdd;
typedef vector<pdd> vpdd;
typedef pair<float, float> pff;
const int MOD = (int)1e9 + 7;
typedef double real;

void load(int k = 1) {
	if (k == 1)	{
#ifndef ONLINE_JUDGE
		freopen("in", "r", stdin);
		freopen("out", "w", stdout);
#endif
	} else if (k == 2) {
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	} else {
		freopen("in", "w", stdout);
	}
}

const int N = (int)1e5 + 1;
const int M = 3000;

void solve() {
	int c;
	stack<char> s;
	int res = 0, n = 0;
	while ((c = getchar()) != EOF) {
		++n;
		if (c == '(') {
			s.push(c);
		} else if (c == ')') {
			if (s.size()) {
				s.pop();
			} else {
				++res;
			}
		}
	}
	cout << n - (res + s.size());
}

void solve2() {

}

#define TIME_CHECK

int main() {
#ifndef ONLINE_JUDGE
#ifdef TIME_CHECK
	double c1 = clock();
#endif
#endif

	load();
	solve();

#ifndef ONLINE_JUDGE
#ifdef TIME_CHECK
	double c2 = clock();
	cout << endl << "time: " << (c2 - c1) / (CLOCKS_PER_SEC / 1000);
#endif
#endif
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <math.h>
#include <conio.h>
#include <utility>
#include <set>
#include <time.h>
#include <list>
#include <typeinfo>
#include <cstdio>
#include <numeric>
#include <limits>
#include <functional>
#include <stack>
using namespace std;
#define X first
#define Y second
#define PI 3.1415926535897932384626433832795
#define PI2 PI * 2
#define sqr(x) ((x)*(x))
#define all(n) (n).begin(), (n).end()
typedef long long LL;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef pair<double, double> pdd;
typedef vector<pdd> vpdd;
typedef pair<float, float> pff;
const int MOD = (int)1e9 + 7;
typedef double real;

void load(int k = 1) {
	if (k == 1)	{
#ifndef ONLINE_JUDGE
		freopen("in", "r", stdin);
		freopen("out", "w", stdout);
#endif
	} else if (k == 2) {
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	} else {
		freopen("in", "w", stdout);
	}
}

const int N = (int)1e5 + 1;
const int M = 3000;

void solve() {
	int c;
	stack<char> s;
	int res = 0, n = 0;
	while ((c = getchar()) != EOF) {
		++n;
		if (c == '(') {
			s.push(c);
		} else {
			if (s.size()) {
				s.pop();
			} else {
				++res;
			}
		}
	}
	cout << n - (res + s.size());
}

void solve2() {

}

#define TIME_CHECK

int main() {
#ifndef ONLINE_JUDGE
#ifdef TIME_CHECK
	double c1 = clock();
#endif
#endif

	load();
	solve();

#ifndef ONLINE_JUDGE
#ifdef TIME_CHECK
	double c2 = clock();
	cout << endl << "time: " << (c2 - c1) / (CLOCKS_PER_SEC / 1000);
#endif
#endif
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	char a[1000009];
	cin>>a;
	int t=0,r=0;
	for(int i=0;i<strlen(a);i++)
	{
		if(a[i]=='(')
			t++;
		if(a[i]==')'&&t>0)
		{
			t--;
			r++;
		}

	}
	cout<<2*r<<endl;
}


#include<iostream>
using namespace std;
int main()
{
	char a[100009];
	cin>>a;
	int t=0,r=0;
	for(int i=0;i<strlen(a);i++)
	{
		if(a[i]=='(')
			t++;
		if(a[i]==')'&&t>0)
		{
			t--;
			r++;
		}

	}
	cout<<2*r<<endl;
}


#include<iostream>
#include<vector>
using namespace std;
vector<char> Brackets; char Ch; int Res;
void main()
{
    while((Ch=getchar())!=EOF) Ch=='('? Brackets.push_back(Ch) : Brackets.empty()? 1 : (Brackets.pop_back(),Res+=2);
    cout<<Res;
}


#include<iostream>
#include<stack>
using namespace std;
stack<char> Brckt; char Ch; int Res;
void main()
{
    while(cin>>Ch) Ch=='('? Brckt.push(Ch) : Brckt.empty()? 1 : (Brckt.pop(),Res+=2);
    cout<<Res;
}


#include <iostream>
#include <string>

using namespace std;

int main(){
	string s;

	getline (cin,s);
	int d=0;
	int ans=s.length();
	for (int i=0;i<s.length();i++){
		if (d<0) ans--;
		else if (s[i]=='(')d++;
		else d--;
	}
	if (d<0) ans--;
	cout<<ans;
	return 0;
}


#include <iostream>
#include <string>

using namespace std;

int main(){
	string s;

	getline (cin,s);
	int d=0;
	int ans=s.length();
	for (int i=0;i<s.length();i++){
		if (d<0) ans--;
		else if (s[i]=='(')d++;
		else d--;
	}
	if (d<0) ans--;
	if (d>0) ans-=d;
	cout<<ans;
	return 0;
}


#include <iostream>
#include <string>

using namespace std;

int main(){
	string s;

	getline (cin,s);
	int d=0;
	int ans=s.length();
	for (int i=0;i<s.length();i++){
		if (d<0) {ans--;d=0;}
		if (s[i]=='(')d++;
		else d--;
	}
	if (d<0) {ans--;d=0;}
	if (d>0) ans-=d;
	cout<<ans;
	return 0;
}


#include <iostream>
#include<stack>
#include<string>
#include<cmath>
using namespace std;

void main(){
	string n;
	stack<char> s;
	int length;
	int count1 = 0, count2 = 0;

	cin >> n;

	length = n.length();

	for(int i = 0; i < n.length(); i++){
		s.push(n[i]);
		}

	while(!s.empty()){
		if(s.top() == '('){
		count1++;
		s.pop();
			}

		else
			break;
		}

	while(!s.empty()){
		if(s.top() == ')')
			count2++;

		else
			count2--;

		s.pop();
	}

	length -= count1 + abs(count2);

	if(length < 0){
		length = 0;
		}

	cout << length << endl;
}


#include <iostream>
#include<stack>
#include<string>
#include<cmath>
using namespace std;

void main(){
	string n;
	stack<char> s;
	int length;
	int count1 = 0, count2 = 0;

	cin >> n;

	length = n.length();

	for(int i = 0; i < n.length(); i++){
		s.push(n[i]);
		}

	while(s.top() == '(' && !s.empty()){
		s.pop();
		count1++;
		}

	while(!s.empty()){
		if(s.top() == ')')
			count2++;

		else
			count2--;
		s.pop();

		}

	length -= count1 + abs(count2);

	if(length < 0){
		length = 0;
		}

	cout << length << endl;
}


#include <iostream>
#include<stack>
#include<string>
#include<cmath>
using namespace std;

void main(){
	string n;
	stack<char> s,s1;
	int length;
	int count = 0, count1 = 0, count2 = 0;

	cin >> n;

	length = n.length();

	for(int i = 0; i < n.length(); i++){
		s.push(n[i]);
		}

	while(!s.empty()){
		if(s.top() == '('){
		count1++;
		s.pop();
			}
		else
			break;
		}

	while(!s.empty()){
		s1.push(s.top());
		s.pop();
		}

	while(!s1.empty()){
		if(s1.top() == ')'){
			count2++;
			s1.pop();
			}
		else
			break;

		}

	while(!s1.empty()){
		if(s1.top() == ')')
			count++;

		else
			count--;

		s1.pop();
	}

	length -= count1 + count2 + abs(count);

	if(length < 0){
		length = 0;
		}

	cout << length << endl;
}


#include <iostream>
#include<stack>
#include<string>
#include<cmath>
using namespace std;

void main(){
	string n;
	stack<char> s;
	int length;
	int count = 0, count1 = 0, count2 = 0;

	cin >> n;

	length = n.length();

	for(int i = 0; i < length; i++){
		s.push(n[i]);
		}

	while(!s.empty()){
		if(s.top() == ')')
			count++;

		else{
			if(count > 0)
				count--;
			else
				count1++;
			}

		s.pop();
		}

	length-= count+count1;

	if(length < 0)
		length = 0;

	cout << length << endl;
}


#include <iostream>
#include<stack>
#include<string>
#include<cmath>
using namespace std;

void main(){
	string n;
	stack<char> s;
	int length;
	int count1 = 0, count2 = 0;

	cin >> n;

	length = n.length();

	for(int i = 0; i < n.length(); i++){
		s.push(n[i]);
		}

	while(s.top() == '('){
		s.pop();
		count1++;
		}

	while(!s.empty()){
		if(s.top() == ')')
			count2++;

		else
			count2--;
		s.pop();

		}

	length -= count1 + abs(count2);

	if(length < 0){
		length = 0;
		}

	cout << length << endl;
}


#include <stdio.h>
#include<stack>
#include<iostream>
#include<queue>
#include<algorithm>
#include<string>
using namespace std;

int main()
{
    string n;
    int count = 0, count1 = 0;
    int answer = 0;
    cin >> n;

    for(int i = n.length() - 1; i >= 0; i--){
        if(n[i] == ')'){
            count++;
        } else{
            if(count > 0){
                count--;
            } else{
                count1++;
            }
        }
    }

    answer = n.length() - count - count1;
    if(answer < 0){
        answer = 0;
    }

    cout << answer << endl;
}


#include<iostream>
#include<string>
#include<stack>

using namespace std;
int main()
{
	string s;
	cin >> s;
	int sum =0 ;
	stack <char > q;
	for (int i = 0; i < s.size(); i++){
		if (!q.empty() && q.top() =='(' &&  s[i]==')'){
		sum+=2;
			q.pop();

		}
		else
			q.push(s[i]);

	}
	cout <<sum;

	return 0;
}


#include<iostream>
#include<cstring>
#include<string>
using namespace std;
char stack[1000001];
int Pointer;
void main(){
	string s;
	cin>>s;
	for(int i=0;i<s.length();i++){
		if(s.at(i)==')' && stack[Pointer-1]=='(')stack[Pointer-1]='\0',Pointer-=1;
		else stack[Pointer++]=s.at(i);
	}
	cout<<s.length()-strlen(stack)<<endl;
}


#include <iostream>

using namespace std;

int main()
{
    int n,h,k,c=0,i,s=0;
    cin>>n>>h>>k;
    int a[n+1];
    a[n]=0;
    for(i=0;i<n;i++)
    {
        cin >> a[i];
    }
    i=0;
    while(a[i]!=0)
    {
        do
        {
            if(a[i]==0)
            {
                while(s>0)
                {
                    s=s-k;
                    c++;
                }
                cout << c ;
                return 0 ;
            }
            s=a[i]+s;
            i++;

        }
        while(s<h);
        if(s>h)
        {
            s=s-a[i-1];
            i--;
        }
        s=s-k;
        c++;
        if(a[i]==0)
        {
            while(s>0)
            {
                s=s-k;
                c++;
            }
            break;
        }
        if(s<0)
        {
            s=0;
        }
    }
    cout << c ;
    return 0;
}


#include <bits/stdc++.h>

#define INF (int)10e6
#define eps 10e-6
#define mp make_pair
#define pub push_back
#define pob pop_back
#define all(t) t.begin(),t.end()
#define LL long long
#define MOD 1000000007
#define fr(i, X) for(int i = 0 ; i < X ; i++)
#define fr1(i, X) for(int i = 1 ; i <= X ; i++)
#define frev(i, X) for(int i = n-1 ; i >= 0 ; i--)
#define frev1(i, X) for(int i = n ; i > 0 ; i--)
#define rt return

using namespace std;

//ifstream fin ("input.txt");
//ofstream fout ("output.txt");
LL n, h, k, a[100001], cnt, sumx, g;
int main()
{
	std::ios::sync_with_stdio(false);
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	cin >> n >> h >> k;
	fr(i, n)
	{
		cin >> a[i];
	}
	while(sumx <= h)
	{
		if(sumx + a[g] <= h)
		{
			sumx += a[g];
			g++;
		}
		else
		{
			if(sumx <= k)
			{
				cnt++;
				sumx = 0;
			}
			else
			{
				cnt += sumx/k;
				sumx %= k;
			}
		}
		if(g >= n)
		{
			cnt += ceil((float)sumx/k);
			break;
		}
	}
	cout << cnt;
}


#include <bits/stdc++.h>

#define INF (int)10e6
#define eps 10e-6
#define mp make_pair
#define pub push_back
#define pob pop_back
#define all(t) t.begin(),t.end()
#define LL long long
#define MOD 1000000007
#define fr(i, X) for(int i = 0 ; i < X ; i++)
#define fr1(i, X) for(int i = 1 ; i <= X ; i++)
#define frev(i, X) for(int i = n-1 ; i >= 0 ; i--)
#define frev1(i, X) for(int i = n ; i > 0 ; i--)
#define rt return

using namespace std;

//ifstream fin ("input.txt");
//ofstream fout ("output.txt");
LL n, h, k, a[100001], cnt, sumx, g;
int main()
{
	std::ios::sync_with_stdio(false);
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	cin >> n >> h >> k;
	fr(i, n)
	{
		cin >> a[i];
	}
	while(sumx <= h)
	{
		if(sumx + a[g] <= h)
		{
			sumx += a[g];
			g++;
		}
		else
		{
			if(sumx <= k)
			{
				cnt++;
				sumx = 0;
			}
			else
			{
				cnt += sumx/k;
				sumx %= k;
			}
		}
		if(g > n)
		{
			if((sumx+1) < k)
			cnt++;
			else if(k == 1)
			cnt += sumx;
			else
			cnt += (sumx+1)/k;
			break;
		}
	}
	cout << cnt;
}


#include <bits/stdc++.h>

#define INF (int)10e6
#define eps 10e-6
#define mp make_pair
#define pub push_back
#define pob pop_back
#define all(t) t.begin(),t.end()
#define LL long long
#define MOD 1000000007
#define fr(i, X) for(int i = 0 ; i < X ; i++)
#define fr1(i, X) for(int i = 1 ; i <= X ; i++)
#define frev(i, X) for(int i = n-1 ; i >= 0 ; i--)
#define frev1(i, X) for(int i = n ; i > 0 ; i--)
#define rt return

using namespace std;

//ifstream fin ("input.txt");
//ofstream fout ("output.txt");
LL n, h, k, a[100001], cnt, sumx, g;
int main()
{
	std::ios::sync_with_stdio(false);
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	cin >> n >> h >> k;
	fr(i, n)
	{
		cin >> a[i];
	}
	a[n] = INF;
	while(sumx <= h)
	{
		if(sumx + a[g] <= h)
		{
			sumx += a[g];
			g++;
		}
		else
		{
			if(sumx - k < 0)
			{
				sumx = 0;
			}
			else
			{
				sumx -= k;
			}
			cnt++;
		}
		if(g >= n)
		{
			if((sumx+1) < k)
			cnt++;
			else
			cnt += (sumx+1)/k;
			break;
		}
	}
	cout << cnt;
}


#include <bits/stdc++.h>

#define INF (int)10e6
#define eps 10e-6
#define mp make_pair
#define pub push_back
#define pob pop_back
#define all(t) t.begin(),t.end()
#define LL long long
#define MOD 1000000007
#define fr(i, X) for(int i = 0 ; i < X ; i++)
#define fr1(i, X) for(int i = 1 ; i <= X ; i++)
#define frev(i, X) for(int i = n-1 ; i >= 0 ; i--)
#define frev1(i, X) for(int i = n ; i > 0 ; i--)
#define rt return

using namespace std;

//ifstream fin ("input.txt");
//ofstream fout ("output.txt");
LL n, h, k, a[100001], cnt, sumx, g;
int main()
{
	std::ios::sync_with_stdio(false);
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	cin >> n >> h >> k;
	fr(i, n)
	{
		cin >> a[i];
	}
	while(sumx <= h)
	{
		if(sumx + a[g] <= h)
		{
			sumx += a[g];
			g++;
		}
		else
		{
			if(sumx <= k)
			{
				cnt++;
				sumx = 0;
			}
			else
			{
				cnt += sumx/k;
				sumx %= k;
			}
		}
		if(g >= n)
		{
			if((sumx+1) < k)
			cnt++;
			if(k == 1)
			{
				cnt += sumx/k;
			}
			else
			{
				cnt += (sumx+1)/k;
			}
			break;
		}
	}
	cout << cnt;
}


#include <bits/stdc++.h>

#define INF (int)10e6
#define eps 10e-6
#define mp make_pair
#define pub push_back
#define pob pop_back
#define all(t) t.begin(),t.end()
#define LL long long
#define MOD 1000000007
#define fr(i, X) for(int i = 0 ; i < X ; i++)
#define fr1(i, X) for(int i = 1 ; i <= X ; i++)
#define frev(i, X) for(int i = n-1 ; i >= 0 ; i--)
#define frev1(i, X) for(int i = n ; i > 0 ; i--)
#define rt return

using namespace std;

//ifstream fin ("input.txt");
//ofstream fout ("output.txt");
LL n, h, k, a[100001], cnt, sumx, g;
int main()
{
	std::ios::sync_with_stdio(false);
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	cin >> n >> h >> k;
	fr(i, n)
	{
		cin >> a[i];
	}
	a[n] = INF;
	while(sumx <= h)
	{
		if(sumx + a[g] <= h)
		{
			sumx += a[g];
			g++;
		}
		else
		{
			if(sumx - k < 0)
			{
				sumx = 0;
			}
			else
			{
				sumx -= k;
			}
			cnt++;
		}
		if(g >= n)
		{
			cnt += (sumx+1)/k;
			break;
		}
	}
	cout << cnt;
}


#include <bits/stdc++.h>

#define INF (int)10e6
#define eps 10e-6
#define mp make_pair
#define pub push_back
#define pob pop_back
#define all(t) t.begin(),t.end()
#define LL long long
#define MOD 1000000007
#define fr(i, X) for(int i = 0 ; i < X ; i++)
#define fr1(i, X) for(int i = 1 ; i <= X ; i++)
#define frev(i, X) for(int i = n-1 ; i >= 0 ; i--)
#define frev1(i, X) for(int i = n ; i > 0 ; i--)
#define rt return

using namespace std;

//ifstream fin ("input.txt");
//ofstream fout ("output.txt");
LL n, h, k, a[100001], cnt, sumx, g;
int main()
{
	std::ios::sync_with_stdio(false);
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	cin >> n >> h >> k;
	fr(i, n)
	{
		cin >> a[i];
	}
	while(sumx <= h)
	{
		if(sumx + a[g] <= h)
		{
			sumx += a[g];
			g++;
		}
		else
		{
			if(sumx <= k)
			{
				cnt++;
				sumx = 0;
			}
			else
			{
				cnt += sumx/k;
				sumx %= k;
			}
		}
		if(g >= n)
		{
			if((sumx+1) < k)
			cnt++;
			else if(k == 1)
			cnt += sumx;
			else
			cnt += (sumx+1)/k;
			break;
		}
	}
	cout << cnt;
}


#include <bits/stdc++.h>

#define INF (int)10e6
#define eps 10e-6
#define mp make_pair
#define pub push_back
#define pob pop_back
#define all(t) t.begin(),t.end()
#define LL long long
#define MOD 1000000007
#define fr(i, X) for(int i = 0 ; i < X ; i++)
#define fr1(i, X) for(int i = 1 ; i <= X ; i++)
#define frev(i, X) for(int i = n-1 ; i >= 0 ; i--)
#define frev1(i, X) for(int i = n ; i > 0 ; i--)
#define rt return

using namespace std;

//ifstream fin ("input.txt");
//ofstream fout ("output.txt");
LL n, h, k, a[100001], cnt, sumx, g;
int main()
{
	std::ios::sync_with_stdio(false);
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	cin >> n >> h >> k;
	fr(i, n)
	{
		cin >> a[i];
	}
	a[n] = INF;
	while(sumx <= h)
	{
		if(sumx + a[g] <= h)
		{
			sumx += a[g];
			g++;
		}
		else
		{
			if(sumx - k < 0)
			{
				sumx = 0;
			}
			else
			{
				sumx -= k;
			}
			cnt++;
		}
		if(g >= n)
		{
			if((sumx+1) < k)
			cnt++;
			else
			while(sumx > 0)
			{
				cnt++;
				sumx -= k;
			}
			break;
		}
	}
	cout << cnt;
}


#include <bits/stdc++.h>

#define INF (int)10e6
#define eps 10e-6
#define mp make_pair
#define pub push_back
#define pob pop_back
#define all(t) t.begin(),t.end()
#define LL long long
#define MOD 1000000007
#define fr(i, X) for(int i = 0 ; i < X ; i++)
#define fr1(i, X) for(int i = 1 ; i <= X ; i++)
#define frev(i, X) for(int i = n-1 ; i >= 0 ; i--)
#define frev1(i, X) for(int i = n ; i > 0 ; i--)
#define rt return

using namespace std;

//ifstream fin ("input.txt");
//ofstream fout ("output.txt");
LL n, h, k, a[100001], cnt, sumx, g;
int main()
{
	std::ios::sync_with_stdio(false);
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	cin >> n >> h >> k;
	fr(i, n)
	{
		cin >> a[i];
	}
	while(sumx <= h)
	{
		if(sumx + a[g] <= h)
		{
			sumx += a[g];
			g++;
		}
		else
		{
			if(sumx - k < 0)
			{
				sumx = 0;
			}
			else
			{
				sumx -= k;
			}
			cnt++;
		}
		if(g >= n)
		{
			if((sumx+1) < k)
			cnt++;
			else if(k == 1)
			cnt += sumx;
			else
			cnt += (sumx+1)/k;
			break;
		}
	}
	cout << cnt;
}


#include <bits/stdc++.h>

#define INF (int)10e6
#define eps 10e-6
#define mp make_pair
#define pub push_back
#define pob pop_back
#define all(t) t.begin(),t.end()
#define LL long long
#define MOD 1000000007
#define fr(i, X) for(int i = 0 ; i < X ; i++)
#define fr1(i, X) for(int i = 1 ; i <= X ; i++)
#define frev(i, X) for(int i = n-1 ; i >= 0 ; i--)
#define frev1(i, X) for(int i = n ; i > 0 ; i--)
#define rt return

using namespace std;
//10 1000000000 1
//999999999 999999999 999999999 999999999
//999999999 999999999 999999999 999999999
//999999999 999999999
//ifstream fin ("input.txt");
//ofstream fout ("output.txt");
LL n, h, k, a[100001], cnt, sumx, g;
int main()
{
	std::ios::sync_with_stdio(false);
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	cin >> n >> h >> k;
	fr(i, n)
	{
		cin >> a[i];
	}
	while(sumx <= h)
	{
		if(sumx + a[g] <= h)
		{
			sumx += a[g];
			g++;
		}
		else
		{
			if(sumx <= k)
			{
				cnt++;
				sumx = 0;
			}
			else
			{
				cnt += sumx/k;
				sumx %= k;
			}
		}
		if(g >= n)
		{
			cnt += (sumx + k - 1)/k;
			break;
		}
	}
	cout << cnt;
}


#include <bits/stdc++.h>

#define INF (int)10e6
#define eps 10e-6
#define mp make_pair
#define pub push_back
#define pob pop_back
#define all(t) t.begin(),t.end()
#define LL long long
#define MOD 1000000007
#define fr(i, X) for(int i = 0 ; i < X ; i++)
#define fr1(i, X) for(int i = 1 ; i <= X ; i++)
#define frev(i, X) for(int i = n-1 ; i >= 0 ; i--)
#define frev1(i, X) for(int i = n ; i > 0 ; i--)
#define rt return

using namespace std;

//ifstream fin ("input.txt");
//ofstream fout ("output.txt");
LL n, h, k, a[100001], cnt, sumx, g;
int main()
{
	std::ios::sync_with_stdio(false);
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	cin >> n >> h >> k;
	fr(i, n)
	{
		cin >> a[i];
	}
	while(sumx <= h)
	{
		if(sumx + a[g] <= h)
		{
			sumx += a[g];
			g++;
		}
		else
		{
//			if(sumx - k < 0)
//			{
//				sumx = 0;
//			}
//			else
//			{
//				sumx -= k;
//			}
			if(sumx <= k)
			{
				cnt++;
				sumx = 0;
			}
			cnt += sumx/k;
			sumx %= k;
		}
		if(g >= n)
		{
			if((sumx+1) < k)
			cnt++;
			else if(k == 1)
			cnt += sumx;
			else
			cnt += (sumx+1)/k;
			break;
		}
	}
	cout << cnt;
}


#include <bits/stdc++.h>

#define INF (int)10e6
#define eps 10e-6
#define mp make_pair
#define pub push_back
#define pob pop_back
#define all(t) t.begin(),t.end()
#define LL long long
#define MOD 1000000007
#define fr(i, X) for(int i = 0 ; i < X ; i++)
#define fr1(i, X) for(int i = 1 ; i <= X ; i++)
#define frev(i, X) for(int i = n-1 ; i >= 0 ; i--)
#define frev1(i, X) for(int i = n ; i > 0 ; i--)
#define rt return

using namespace std;

//ifstream fin ("input.txt");
//ofstream fout ("output.txt");
LL n, h, k, a[100001], cnt, sumx, g;
int main()
{
	std::ios::sync_with_stdio(false);
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	cin >> n >> h >> k;
	fr(i, n)
	{
		cin >> a[i];
	}
	while(sumx <= h)
	{
		if(sumx + a[g] <= h)
		{
			sumx += a[g];
			g++;
		}
		else
		{
			if(sumx <= k)
			{
				cnt++;
				sumx = 0;
			}
			else
			{
				cnt += sumx/k;
				sumx %= k;
			}
		}
		if(g >= n)
		{
			if((sumx+1) < k)
			cnt++;
			else
			{
				cnt += sumx/k;
			}
			break;
		}
	}
	cout << cnt;
}


#include<iostream>
#include<math.h>

using namespace std;

int main()
{
    int n,h,k,time=0;
    cin>>n>>h>>k;
    int arr[n];
    int container=0,remain=0;
    for(int i=0;i<n;i++)
       {
           cin>>arr[i];
           remain+=arr[i];
       }

    int i=0;
    while(i!=n)
    {
        for(int j=i;j<n;j++)
        {
            if(container<h)
            {
                if(container+arr[i]<=h)
                {
                    container = container + arr[i];
                    i++;
                }
                else
                    break ;
            }

        }
        if(i<n)
        {
            container = container - k;
            time++ ;
                if(container<0)
                    container = 0;
        }

        else
         {
            time = time + ceil(container/k);
         }

    }

    cout<<time ;
return 0;
}


#include<iostream>
#include<math.h>

using namespace std;

int main()
{
    int n,h,k,time=0;
    cin>>n>>h>>k;
    int arr[n];
    int container=0,remain=0;
    for(int i=0;i<n;i++)
       {
           cin>>arr[i];
           remain+=arr[i];
       }

    int i=0;
    while(i!=n)
    {
        for(int j=i;j<n;j++)
        {
            if(container<h)
            {
                if(container+arr[i]<=h)
                {
                    container = container + arr[i];
                    i++;
                }
                else
                    break ;
            }
            else
                break;

        }
        if(i<n)
        {
            container = container - k;
            time++ ;
                if(container<0)
                    container = 0;
        }

        else
         {
             if(container%k==0)
                time = time + container/k ;
             else
                time =time + 1 + container/k;
         }

    }

    cout<<time ;
return 0;
}


#include<iostream>

using namespace std;

int main()
{
    int n,h,k,time=0;
    cin>>n>>h>>k;
    int arr[n];
    int container=0;
    for(int i=0;i<n;i++)
       {
           cin>>arr[i];
       }

    int i=0;
    while(i!=n)
    {
        for(int j=i;j<n;j++)
        {
            if(container<h)
            {
                if(container+arr[i]<=h)
                {
                    container = container + arr[i];
                    i++;
                }
                else
                    break ;
            }
            else
                break;

        }
        if(i<n)
        {
            int x = container - (h-arr[i]) ;

            if(x%k==0)
              {
                time = time + x/k ;
                container = container - x;
                 if(container<0)
                container = 0;
              }
            else
            {
                time = time + x/k +1 ;
                container = container - ((x/k)+1)*k ;
                 if(container<0)
                container = 0;
            }

        }

        else
         {
             if(container%k==0)
                time = time + container/k ;
             else
                time =time + 1 + container/k;
         }

    }

    cout<<time ;
return 0;
}


#include<iostream>

using namespace std;

int main()
{
    long long int n,h,k,time=0;
    cin>>n>>h>>k;
    long long int arr[n];
    long long int container=0,remain=0;
    for(long long int i=0;i<n;i++)
       {
           cin>>arr[i];
           remain = remain + arr[i];
       }

    long long int i=0;

    if(k!=1)
       {
        while(i!=n)
        {

            for(long long int j=i;j<n;j++)
            {
                if(container<h)
                {
                    if(container+arr[i]<=h)
                    {
                        container = container + arr[i];
                        i++;
                    }
                    else
                        break ;
                }
                else
                    break;

            }
            if(i<n)
            {
                long long int x = container - (h-arr[i]) ;

                if(x%k==0)
                  {
                    time = time + x/k ;
                    container = container - x;
                     if(container<0)
                    container = 0;
                  }
                else
                {
                    time = time + x/k +1 ;
                    container = container - ((x/k)+1)*k ;
                     if(container<0)
                    container = 0;
                }

            }

            else
             {
                 if(container%k==0)
                    time = time + container/k ;
                 else
                    time =time + 1 + container/k;
             }
        }
            cout<<time ;
       }
        else
           cout<<remain ;

return 0;
}


#include<iostream>

using namespace std;

int main()
{
    int n,h,k,time=0;
    cin>>n>>h>>k;
    int arr[n];
    int container=0,remain=0;
    for(int i=0;i<n;i++)
       {
           cin>>arr[i];
           remain = remain + arr[i];
       }

    int i=0;
    if(k!=1)
       {
        while(i!=n)
        {

            for(int j=i;j<n;j++)
            {
                if(container<h)
                {
                    if(container+arr[i]<=h)
                    {
                        container = container + arr[i];
                        i++;
                    }
                    else
                        break ;
                }
                else
                    break;

            }
            if(i<n)
            {
                int x = container - (h-arr[i]) ;

                if(x%k==0)
                  {
                    time = time + x/k ;
                    container = container - x;
                     if(container<0)
                    container = 0;
                  }
                else
                {
                    time = time + x/k +1 ;
                    container = container - ((x/k)+1)*k ;
                     if(container<0)
                    container = 0;
                }

            }

            else
             {
                 if(container%k==0)
                    time = time + container/k ;
                 else
                    time =time + 1 + container/k;
             }
        }
            cout<<time ;
       }
        else
            cout<<remain ;

return 0;
}


#include<iostream>

using namespace std;

int main()
{
    int n,h,k,time=0;
    cin>>n>>h>>k;
    int arr[n];
    int container=0,remain=0;
    for(int i=0;i<n;i++)
       {
           cin>>arr[i];
           remain = remain + arr[i];
       }

    int i=0;
    if(k!=1)
        while(i!=n)
        {

            for(int j=i;j<n;j++)
            {
                if(container<h)
                {
                    if(container+arr[i]<=h)
                    {
                        container = container + arr[i];
                        i++;
                    }
                    else
                        break ;
                }
                else
                    break;

            }
            if(i<n)
            {
                int x = container - (h-arr[i]) ;

                if(x%k==0)
                  {
                    time = time + x/k ;
                    container = container - x;
                     if(container<0)
                    container = 0;
                  }
                else
                {
                    time = time + x/k +1 ;
                    container = container - ((x/k)+1)*k ;
                     if(container<0)
                    container = 0;
                }

            }

            else
             {
                 if(container%k==0)
                    time = time + container/k ;
                 else
                    time =time + 1 + container/k;
             }

              cout<<time ;

        }

        else
            cout<<remain ;

return 0;
}


#include<iostream>

using namespace std;

int main()
{
    int n,h,k,time=0;
    cin>>n>>h>>k;
    int arr[n];
    int container=0,remain=0;
    for(int i=0;i<n;i++)
       {
           cin>>arr[i];
           remain+=arr[i];
       }

    int i=0;
    while(i!=n)
    {
        for(int j=i;j<n;j++)
        {
            if(container<h)
            {
                if(container+arr[i]<=h)
                {
                    container = container + arr[i];
                    i++;
                }
                else
                    break ;
            }

        }
        if(i<n)
        {
            container = container - k;
            time++ ;
                if(container<0)
                    container = 0;
        }

        else
         {
             while(container>0)
               {
                   container = container - k;
                    time++ ;
               }
         }

    }

    cout<<time ;

return 0;
}


#include<iostream>
#include<math.h>

using namespace std;

int main()
{
    int n,h,k,time=0;
    cin>>n>>h>>k;
    int arr[n];
    int container=0,remain=0;
    for(int i=0;i<n;i++)
       {
           cin>>arr[i];
           remain+=arr[i];
       }

    int i=0;
    while(i!=n)
    {
        for(int j=i;j<n;j++)
        {
            if(container<h)
            {
                if(container+arr[i]<=h)
                {
                    container = container + arr[i];
                    i++;
                }
                else
                    break ;
            }

        }
        if(i<n)
        {
            container = container - k;
            time++ ;
                if(container<0)
                    container = 0;
        }

        else
         {
             if(container%k==0)
                time = time + container/k ;
             else
                time =time + 1 + container/k;
         }

    }

    cout<<time ;
return 0;
}


using namespace std;
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#define ll long long
#define input freopen("input.in","r",stdin);
#define output freopen("output.out","w",stdout);
#define e printf("\n");
#define all(it,v) for(it=(v).begin();it!=(v).end();it++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define pii pair<ll,ll>
typedef vector<vector<ll> > mat;
const ll mx=100001;
const ll mod=1000000007;
const ll inf=0x3f3f3f3f;

ll ar[mx+1];
void solve()
{
	ll h,n,c,k,i,ans=0;
	cin>>n>>h>>k;
	for(i=0;i<n;i++)
	 cin>>ar[i];
	 c=0;
	 i=0;
	 while(1)
	 {
	   if(i==n)
	    {
	    	if(c>0)
	    	 ans++;
	    	break;
		}
	    while(i<n&&c+ar[i]<=h)
		{
			c+=ar[i];
			i++;
	    }
	    if(c>=k)
	    c-=k;
	    else
	    c=0;
	    ans++;
	 }
	 cout<<ans;
}
int main()
{
	solve();
	return 0;
}


using namespace std;
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#define ll long long
#define input freopen("input.in","r",stdin);
#define output freopen("output.out","w",stdout);
#define e printf("\n");
#define all(it,v) for(it=(v).begin();it!=(v).end();it++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define pii pair<ll,ll>
typedef vector<vector<ll> > mat;
const ll mx=100001;
const ll mod=1000000007;
const ll inf=0x3f3f3f3f;

ll ar[mx+1];
void solve()
{
	ll h,n,c,k,i,ans=1;
	cin>>n>>h>>k;
	for(i=0;i<n;i++)
	 cin>>ar[i];
	 c=0;
	 i=0;
	 while(1)
	 {
	   if(i==n)
	    break;
	    while(i<n&&c+ar[i]<=h)
		{
			c+=ar[i];
			i++;
	    }
	    if(c>k)
	    c-=k;
	    else
	    c=0;
	    ans++;
	 }
	 cout<<ans;
}
int main()
{
	solve();
	return 0;
}


using namespace std;
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#define ll long long
#define input freopen("input.in","r",stdin);
#define output freopen("output.out","w",stdout);
#define e printf("\n");
#define all(it,v) for(it=(v).begin();it!=(v).end();it++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define pii pair<ll,ll>
typedef vector<vector<ll> > mat;
const ll mx=100001;
const ll mod=1000000007;
const ll inf=0x3f3f3f3f;

ll ar[mx+1];
void solve()
{
	ll h,n,c,k,i,ans=1;
	cin>>n>>h>>k;
	for(i=0;i<n;i++)
	 cin>>ar[i];
	 c=0;
	 i=0;
	 while(1)
	 {
	   if(i==n)
	    break;
	    while(i<n&&c+ar[i]<=h)
		{
			c+=ar[i];
			i++;
	    }
	    if(c>=k)
	    c-=k;
	    else
	    c=0;
	    ans++;
	 }
	 cout<<ans;
}
int main()
{
	solve();
	return 0;
}


using namespace std;
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#define ll long long
#define input freopen("input.in","r",stdin);
#define output freopen("output.out","w",stdout);
#define e printf("\n");
#define all(it,v) for(it=(v).begin();it!=(v).end();it++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define pii pair<ll,ll>
typedef vector<vector<ll> > mat;
const ll mx=100001;
const ll mod=1000000007;
const ll inf=0x3f3f3f3f;

ll ar[mx+1];
void solve()
{
	ll h,n,c,k,i,ans=0;
	cin>>n>>h>>k;
	for(i=0;i<n;i++)
	 cin>>ar[i];
	 c=0;
	 i=0;
	 while(1)
	 {
	   if(i==n)
	    {
	    	while(c>0)
			{
				c-=k;
				ans++;
			 }
			 break;
		}
	    while(i<n&&c+ar[i]<=h)
		{
			c+=ar[i];
			i++;
	    }
	    if(c>=k)
	    c-=k;
	    else
	    c=0;
	    ans++;
	 }
	 cout<<ans;
}
int main()
{
	solve();
	return 0;
}


using namespace std;
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#define ll long long
#define input freopen("input.in","r",stdin);
#define output freopen("output.out","w",stdout);
#define e printf("\n");
#define all(it,v) for(it=(v).begin();it!=(v).end();it++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define pii pair<ll,ll>
typedef vector<vector<ll> > mat;
const ll mx=100001;
const ll mod=1000000007;
const ll inf=0x3f3f3f3f;

ll ar[mx+1];
void solve()
{
	ll h,n,c,k,i,ans=0;
	cin>>n>>h>>k;
	for(i=0;i<n;i++)
	 cin>>ar[i];
	 c=0;
	 i=0;
	 while(i<n)
     {
     	if(c+ar[i]>h)
     	 ans++;
     	 else
     	 c+=ar[i];
     	ans+=c/k;
		 c%=k;
		 i++;
	 }
	  if(c)
	   ans++;
	 cout<<ans;
}
int main()
{
	solve();
	return 0;
}


using namespace std;
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#define ll long long
#define input freopen("input.in","r",stdin);
#define output freopen("output.out","w",stdout);
#define e printf("\n");
#define all(it,v) for(it=(v).begin();it!=(v).end();it++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define pii pair<ll,ll>
typedef vector<vector<ll> > mat;
const ll mx=100001;
const ll mod=1000000007;
const ll inf=0x3f3f3f3f;

ll ar[mx+1];
void solve()
{
	ll h,n,c,k,i,ans=0,x=0;
	cin>>n>>h>>k;
	 c=0;
	 i=0;
	 while(i<n)
     {
     	cin>>x;
     	if((c+x)>h)
     	 ans++;
     	 else
     	  x+=c;
     	ans+=x/k;
		 c=x%k;
		 i++;
	 }
	  if(c)
	   ans++;
	 cout<<ans;
}
int main()
{
	solve();
	return 0;
}


using namespace std;
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#define ll long long
#define input freopen("input.in","r",stdin);
#define output freopen("output.out","w",stdout);
#define e printf("\n");
#define all(it,v) for(it=(v).begin();it!=(v).end();it++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define pii pair<ll,ll>
typedef vector<vector<ll> > mat;
const ll mx=100001;
const ll mod=1000000007;
const ll inf=0x3f3f3f3f;

ll ar[mx+1];
void solve()
{
	ll h,n,c,k,i,ans=0;
	cin>>n>>h>>k;
	for(i=0;i<n;i++)
	 cin>>ar[i];
	 c=0;
	 i=0;
	 while(1)
	 {
	   if(i==n)
	    {
	    	if(c>0)
			{
			  ans+=c/k;
			  if(c%k)
			  ans++;
			}
			 break;
		}
	    while(i<n&&c+ar[i]<=h)
		{
			c+=ar[i];
			i++;
	    }
	    if(c>=k)
	    c-=k;
	    else
	    c=0;
	    ans++;
	 }
	 cout<<ans;
}
int main()
{
	solve();
	return 0;
}


#include<cstdio>
#include <cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include <map>
using namespace std;

int main()
{
	long long n, h, k, i, a, cur, sec;
	cin>>n>>h>>k;
	cur = sec = 0;
	for (i = 0; i < n; ++i)
	{
		cin>>a;
		if (cur + a <= h)
		{
			cur += a;
		}
		else
		{
			cur = a;
			++sec;
		}
		sec += cur / k;
		cur %= k;
	}
	sec += cur / k;
	cur %= k;
	if (cur > 0)
	{
		++sec;
	}
	cout<<sec;
}


#include<iostream>
#include<cstring>
#include<math.h>
#include<cstdio>
#include<iostream>
#include<algorithm>
#define N 50001
#define maxn 1000001
#define INF 0x3f3f3f3f
#include<map>
#include<string>
#include<queue>
#include<vector>
#include<set>
double pi=acos(-1.0);
using namespace std;
using namespace std;
typedef long long LL;
LL a[100010]={0};
int main()
{
	LL n,h,k;
	cin>>n>>h>>k;
		for(int i=0;i<n;i++)
		{
			scanf("%I64d",&a[i]);
		}
		LL sum=0,ans=0;
		for(int i=0;i<n;i++)
		{
			if(sum+a[i]<=h) sum+=a[i];
			else
			{
				sum=a[i];
				ans++;
			}
			LL t=sum/k;
			ans+=t;
			sum-=t*k;
		}
		if(sum)ans++;
		printf("%I64d\n",ans);

	return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
int a[120000];
int main()
{
    int n,m, k;
    scanf("%d%d%d", &n, &m, &k);
    long long ans = 0;
    for(int i = 0; i < n ; i ++)
    {
        scanf("%d", &a[i]);

    }
    int sum = 0;
    for(int i = 0; i < n - 1; i ++)
    {
        sum += a[i];
        int len = sum / k;
        int t1 = sum % k;
        if(m - t1 -a[i + 1] >= 0)
        {
            int dis = m - t1 - a[i + 1];
            dis = dis / k;
            ans = ans + len - dis;
            sum = k * dis + t1;
        }
        else
        {
            ans = ans + len + 1;
            sum = 0;
        }
        //cout << sum <<endl;
    }
    sum += a[n - 1];
    if(sum % k == 0)
    {
        ans +=(sum / k);
    }
    else
    {
        ans ++;
        ans +=(sum / k);
    }
    printf("%I64d",ans);
}


#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
int cmp(const void *a,const void *b)
{
	return (*(int *)a-*(int *)b);
}
int main()
{
	int n,h1,h2;
	scanf("%d%d%d",&n,&h1,&h2);
	int a[100050];
	for(int i=0;i<n;i++)
	scanf("%d",&a[i]);
	a[n]=h1;
	qsort(a,n,sizeof(int),cmp);
	int t=0;
	int sum=0;
	for(int i=0;i<=n;i++)
	{
		sum+=a[i];
		while(sum+a[i+1]>h1)
		{
			sum-=h2;
			t+=1;
			if(sum<0) sum=0;
		}

	}
	printf("%d",t);

}


#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	int n,h,k;
	long long ans = 0;
	cin>>n>>h>>k;
	int s = 0;
	for(int i = 1;i<=n;i++){
		int t;
		cin>>t;
		if(s + t > h){
			s = 0;
			ans ++;
		}
		ans += (s + t) / k;
		s = (s + t) % k;
	}
	if(s) ans++;
	cout<<ans<<endl;
	return 0;
}


#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
int cmp(const void *a,const void *b)
{
	return (*(int *)a-*(int *)b);
}
int main()
{
	int n,h1,h2;
	scanf("%d%d%d",&n,&h1,&h2);
	int a[100050];
	for(int i=0;i<n;i++)
	scanf("%d",&a[i]);
	a[n]=h1;
	qsort(a,n,sizeof(int),cmp);
	int t=0;
	int sum=0;
	for(int i=0;i<n;i++)
	{
		sum+=a[i];
		if(sum+a[i+1]>h1)
		{
			while(sum>0&&sum+a[i+1]>h1)
			{
				sum-=h2;
				t+=1;
				if(sum<0) sum=0;

			}

		}

	}
	printf("%d",t);

}


#include<iostream>
#include<queue>
using namespace std;
int main()
{
    queue<long long> s;
    long long h,k,n,x,t=0,l=0;
    cin>>n>>h>>k;
    for(int i=0; i<n; i++)
    {
    	cin>>x;
    	s.push(x);
    }
    do
    {
    	while(!s.empty() && l+s.front()<=h)
    	{
    		l+=s.front();
    		s.pop();
    	}
    	if(l<k)
    	{
    		t++;
    		l=0;
    	}
    	t+=l/k;
    	l%=k;
    }while(!s.empty());
    if(l) t++;
    cout<<t<<endl;
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<queue>
using namespace std;
int main()
{
	int i,j,time=0,n,h,k,a[105000],s=0;
	scanf("%d%d%d",&n,&h,&k);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a,a+n);
	s=a[0];i=1;
	while(++time)
	{
		while(i<n)
		{
			if(h-s>=a[i])s+=a[i++];
			else break;
		}
		s-=k;
		if(s<0)s=0;
		if(i==n&&s==0)break;

		//if(h-s>=k&&i<n)s+=a[i++];

	}
	printf("%d\n",time);
	return 0;
}