#include <string.h>
#include <stdlib.h>
#include <stdio.h>
int pos,len;
char line[1000];
int set[30];
char *s;
void get()
{ free(s);
s=(char*)malloc(10);
if(line[pos]=='(')
{ strcpy(s,"(");
pos++;
}
else if(line[pos]==')')
{ strcpy(s,")");
pos++;
}
else if(strncmp(line+pos,"OR",2)==0)
{ strcpy(s,"OR");
pos+=2;
}
else if(strncmp(line+pos,"AND",3)==0)
{ strcpy(s,"AND");
pos+=3;
}
else if(strncmp(line+pos,"NOT",3)==0)
{ strcpy(s,"NOT");
pos+=3;
}
else if(strncmp(line+pos,"TRUE",4)==0)
{ strcpy(s,"TRUE");
pos+=4;
}
else if(strncmp(line+pos,"FALSE",5)==0)
{ strcpy(s,"FALSE");
pos+=5;
}
else
{ s[0]=line[pos];
s[1]=NULL;
pos++;
}
while(line[pos]==' ')
{pos++;}
}
int OR();
int AND();
int NOT();
int expr()
{ int v1;
// printf("expr");
if(strncmp(s,"(",1)==0)
{get();
v1=OR();
get();
return v1;
}
else if(s[0]>='A'&&s[0]<='Z'&&s[1]==0)
{ v1=set[s[0]-'A'];
get();
// printf("--%d--",v1);
return v1;
}
else if(strncmp(s,"TRUE",4)==0)
{ get();
return 1;
}
else if(strncmp(s,"FALSE",5)==0)
{ get();
return 0;
}
}
int OR()
{
//printf("OR");
int v1=AND();
int v2;
while(strncmp(s,"OR",2)==0)
{ get();
v2=AND();
v1=v1 or v2;
}
// printf("OR %d\n",v1);
return v1;
}
int AND()
{
//printf("AND");
int v1=NOT();
int v2;
while(strncmp(s,"AND",3)==0)
{ get();
// printf("nu merge");
v2=NOT();
v1=v1 and v2;
}
// printf("AND %d\n",v1);
return v1;
}
int NOT()
{ //printf("NOT");
int v1=0;
while(strncmp(s,"NOT",3)==0)
{ get();
v1=1-v1;
}
int t=v1^expr();
// printf("NOT %d\n",t);
return t;
}
int main ()
{ int n;
char str[104];
FILE *f=fopen("bool.in","r");
freopen("bool.out","w",stdout);
fgets(line,1000,f);
line[strlen(line)-1]=0;
len=strlen(line);
fscanf(f,"%d %s",&n,str);
for(char c='A';c<='Z';c++)
{ set[c-'A']=0;
}
for(int i=0;i<n;i++)
{ set[str[i]-'A']=1-set[str[i]-'A'];
/*for(char c='A';c<='Z';c++)
{ printf("%d",set[c-'A']);
}
printf("\n");*/
pos=0;
get();
printf("%d",OR());
}
return 0;
}