type ar=record
x,y:longint end;
var i,j,l,z,t:longint;
t3,ze:ar;
c:array[0..100003]of char;
v,s:array[0..100003]of longint;
function find(l,r:longint):ar;
var i:longint;
t1,t2:ar;
begin
if l>r then exit(ze);
i:=r;
while i>=l do begin if c[i]=')' then i:=v[i];
if (c[i]='+') then break; dec(i); end;
if i<l then begin i:=r; while i>=l do begin if c[i]=')' then i:=v[i];
if (c[i]='*') then break; dec(i); end;
if i<l then exit(find(l+1,r-1)); end;
t1:=find(l,i-1); t2:=find(i+1,r);
if c[i]='+' then begin
find.x:=((t1.x*t2.x)mod 10007);
find.y:=(t1.x*t2.y+t1.y*t2.x+t1.y*t2.y)mod 10007;
exit(find);
end else begin
find.x:=(t1.x*t2.y+t1.x*t2.x+t1.y*t2.x)mod 10007;
find.y:=(t1.y*t2.y)mod 10007;
exit(find);
end;
end;
begin
assign(input,'t1.in');
assign(output,'t1.out');
reset(input);
rewrite(output);
readln(l); for i:=1 to l do read(c[i]);
ze.x:=1; ze.y:=1;
for i:=1 to l do
begin
if c[i]='(' then begin inc(z); s[z]:=i; end;
if c[i]=')' then begin v[i]:=s[z]; dec(z);end;
end;
t3:=find(1,l); writeln(t3.x);
close(input);
close(output);
end.
答案绝对都是对的就是栈溢出,但是计算了一下并不栈溢出