rt,本地运行无法输出结果
%:include<bits/stdc++.h>
//#define int long long
#define qwert std::cout<<"\n"
#define asdf std::cout<<" ";
inline int read()<%
int s=0;
int w=1;
char ch=getchar();
for(;ch<'0'||ch>'9';ch=getchar())
if(ch=='-')
w=-1;
for(;ch>='0' and ch<='9';ch=getchar())
s=s*10+ch-'0';
return s*w;
%>
void write(int x)<%
if(x<0)<%
putchar('-');
x=-x;
%>
if(x>9)
write(x/10);
putchar(x%10+'0');
return;
%>
int n;
std::stack<int>u,v;
std::string s;
std::queue<char>q;
std::stack<char>st;
int main(){
n=read();
std::cin>>s;
s=" "+s;
q.push('\0');
for(int i=1;i<=n;i++){
if(s[i]=='('||s[i]=='*')
st.push(s[i]);
if(s[i]=='+'){
while(!st.empty()&&st.top()=='*'){
q.push(st.top());
st.pop();
}
st.push(s[i]);
}
if(s[i]==')'){
while(st.top()!='('){
q.push(st.top());
st.pop();
}
st.pop();
}
if(s[i]!='('&&s[i]!=')')
q.push('\0');
}
while(!st.empty()){
q.push(st.top());
st.pop();
}
while(!q.empty()){
if(q.front()=='\0'){
u.push(1);
v.push(1);
}
if(q.front()=='*'){
int x=u.top();
u.pop();
int y=u.top();
u.pop();
int a=v.top();
v.pop();
int b=v.top();
v.pop();
y=(x*b+y*a+x*y)%10007;
u.push(y);
// u[top]=(u[top+1]*v[top]+u[top]*v[top+1]+u[top]*u[top+1])%M;
b=b*a%10007;
v.push(b);
// v[top]=v[top]*v[top+1]%M;
}
if(q.front()=='+'){
int x=u.top();
u.pop();
int y=u.top();
u.pop();
int a=v.top();
v.pop();
int b=v.top();
v.pop();
b=(x*b+y*a+a*b)%10007;
y=y*x%10007;
v.push(y);
u.push(b);
// v[top]=(u[top+1]*v[top]+u[top]*v[top+1]+v[top]*v[top+1])%M;
// u[top]=u[top]*u[top+1]%M;
}
}
write(u.top());
return 0;
}