You are a researcher investigating algorithms on binary trees. Binary tree is a data structure composed of branch nodes and leaf nodes. Every branch nodes have left child and right child, and each child is either a branch node or a leaf node. The root of a binary tree is the branch node which has no parent.

You are preparing for your presentation and you have to make a figure of binary trees using a software. You have already made a figure corresponding to a binary tree which is composed of one branch node and two leaf nodes (Figure 1.) However, suddenly the function of your software to create a figure was broken. You are very upset because in five hours you have to make the presentation in front of large audience.

You decided to make the figure of the binary trees using only copy function, shrink function and paste function of the presentation tool. That is, you can do only following two types of operations.

* Copy the current figure to the clipboard.

* The figure copied to the clipboard before is removed.

* Paste the copied figure (with shrinking, if needed), putting the root of the pasted figure on a leaf node of the current figure.

* You can paste the copied figure multiple times.




Moreover, you decided to make the figure using the minimum number of paste operations because paste operation is very time cosuming. Now, your job is to calculate the minimum possible number of paste operations to produce the target figure.

<image>

Figure 1: initial state

For example, the answer for the instance of sample 1(Figure 4) is 3, because you can produce the target figure by following operations and this is minimum.

<image>

Figure 2: intermediate 1

<image>

Figure 3: intermediate 2

<image>

Figure 4: Goal



Input

The input is a line which indicates a binary tree. The grammar of the expression is given by the following BNF.

> <tree> ::= <leaf> | "(" <tree> <tree> ")"
> <leaf> ::= "()"
>

Every input obeys this syntax. You can assume that every tree in the input has at least 1 branch node, and that it has no more than 10^5 branch nodes.

Output

A line containing the minimum possible number of paste operations to make the given binary tree.

Examples

Input

((()())(((()())(()()))()))


Output

3


Input

(((()())(()()))(()()))


Output

4


Input

((()(()()))((()(()()))()))


Output

3


Input

(()())


Output

0
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
using vi=vector<int>;
#define PB push_back
#define ALL(x) x.begin(),x.end()
	
const int Nmax=415514;
const int inf=1145141919;
char tree[Nmax],buf[Nmax];
int sub[Nmax],idx;
int dfs1(char*&p){
	if(*++p==')')return 0;
	int v=idx++,res=1;
	REP(_,2){
		res+=dfs1(p);
		p++;
	}
	return sub[v]=res;
}
bool check(int&i,char c){
	if(buf[i]=='?')buf[i]=c;
	else if(buf[i]!=c)return false;
	i++;
	return true;
}
bool dfs2(char*&p,int w,int*i){
	if(*++p==')')return true;
	int v=idx++,tmp=0;
	if(sub[v]%w==0)i=&tmp;
	REP(_,2){
		if(!check(*i,*p))return false;
		if(!dfs2(p,w,i))return false;
		if(!check(*i,*p))return false;
		p++;
	}
	return true;
}

int main(){
	scanf("%s",tree);
	char* beg=tree;
	dfs1(beg);
	int n=sub[0];
	vi canUse;
	FOR(i,1,n+1)if(n%i==0){
		beg=tree;
		REP(j,4*i)buf[j]='?';
		idx=0;
		if(dfs2(beg,i,0))
			canUse.PB(i);
	}
	vi dp(canUse.size(),inf);
	dp[0]=0;
	REP(i,dp.size())FOR(j,i+1,dp.size())if(canUse[j]%canUse[i]==0)
		dp[j]=min(dp[j],dp[i]+canUse[j]/canUse[i]-1);
	cout<<dp.back()<<endl;
}