#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#define N 31
int stack[N];
int top = -1;
int cnt=0;
void push(int data)
{
stack[++top] = data;
}
int pop()
{
return stack[top--];
}
int main()
{
int b,c,d=0;
char a[50];
gets(a);
int cal=1, res=0;
for(int i=0; i<strlen(a); i++)
{
if(a[i]!='('&&a[i]!=')'&&a[i]!='['&&a[i]!=']')
break;
if(a[i]=='(')
{
push(-1);
}
else if(a[i]=='[')
{
push(-2);
}
else if(a[i]==')')
{
b=0;
while(stack[top] != -1)
{
if(top==-1)
{
printf("0");
return 0;
}
b+=pop();
}
pop();
if(b==0)
push(2);
else
push(b*2);
}
/*
if(a[i-1]=='(')
{
b=pop();
res=b*cal;
push(res);
b=0;
}
else
{
b+=pop();
}
res+=d;
d=0;
cal/=2;
}
*/
else if(a[i]==']')
{
c=0;
while(stack[top]!= -2)
{
if(top==-1)
{
printf("0");
return 0;
}
c+=pop();
}
pop();
if(c==0)
push(3);
else
push(c*3);
}
}
while(top!=-1)
{
if(stack[top]==-1|| stack[top]==-2)
{
printf("0");
return 0;
}
d+=pop();
}
printf("%d",d);
}
/*
if(cnt==0)
{
printf("%d", res);
}
else printf("0");
}
*/



