本地都能过可是交上去就全 WA
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#define mod 1000000007
#define N 105
#define ll long long
using namespace std;
char s[N],ans[N];
int len,tot,n;
ll num;
string last_ans;
bool vis[N];
int pd(char x){
if(x=='^') return 3;
if(x=='*' || x=='/') return 2;
if(x=='+' || x=='-') return 1;
return 0;
}
ll get(int st){
ll res=0;
for(int i=st;i<=tot;i++)
if(ans[i]>='0' && ans[i]<='9')
res=res*10+(ans[i]-'0'),vis[i]=1;
else return res;
}
ll pow(ll a,ll b){
while(b--)
a=a*a%mod;
return a;
}
void read(){
len=0;
char x;
while(1){
scanf("%c",&x);
if(x=='\n') return;
if(x!=' ') s[++len]=x;
}
}
void change(char *s){
tot=0;
char sta[N]="";
int top=0;
for(int i=1;i<=len;i++){
if(s[i]>='0' && s[i]<='9'){
while(i<=len && s[i]>='0' && s[i]<='9')
ans[++tot]=s[i++];
ans[++tot]='#';
i--;
}
else if(s[i]=='a') ans[++tot]='a';
else{
if(s[i]=='(') sta[++top]=s[i];
else if(s[i]==')'){
while(top && sta[top]!='(')
ans[++tot]=sta[top--];
--top;
}
else{
int dj=pd(s[i]);
while(top && pd(sta[top])>=dj)
ans[++tot]=sta[top--];
sta[++top]=s[i];
}
}
}
while(top)
ans[++tot]=sta[top--];
}
ll work(){
memset(vis,0,sizeof(vis));
ll sta[N]={0};
int top=0;
for(int i=1;i<=tot;i++){
if(vis[i] || ans[i]=='#' || ans[i]=='(') continue;
if(ans[i]>='0' && ans[i]<='9' && !vis[i]) sta[++top]=get(i);
else if(ans[i]=='a') sta[++top]=131;
else{
ll x=sta[top],y=sta[--top];
if(ans[i]=='+') sta[top]=((x+y)%mod+mod)%mod;
else if(ans[i]=='^') sta[top]=(pow(y,x)%mod+mod)%mod;
else if(ans[i]=='-') sta[top]=((y-x)%mod+mod)%mod;
else if(ans[i]=='*') sta[top]=((x*y)%mod+mod)%mod;
}
}
return (sta[top]%mod+mod)%mod;
}
int main(){
read();
change(s);
num=work();
scanf("%d",&n);
for(int i=0;i<=n;i++){
read();
change(s);
if(num==work()) last_ans+=(i+'A'-1);
}
cout<<last_ans;
return 0;
}