var yx:array[chr(1)..chr(127)]of longint;
st,s:array[0..1000000]of char;
f:array[0..1000000,0..1]of longint;
top,top2,i,j,n:longint;
LAST:string;
procedure pop;
begin
if st[top]='+' then
begin
f[top2,1]:=f[top2-1,0]*f[top2,1]+f[top2-1,1]*f[top2,0]+f[top2-1,1]*f[top2,1];
f[top2,1]:=f[top2,1] mod 10007;
f[top2,0]:=f[top2-1,0]*f[top2,0];
f[top2,0]:=f[top2,0]mod 10007;
end
else
begin
f[top2,0]:=f[top2-1,0]*f[top2,1]+f[top2-1,1]*f[top2,0]+f[top2-1,0]*f[top2,0];
f[top2,0]:=f[top2,0] mod 10007;
f[top2,1]:=f[top2-1,1]*f[top2,1];
f[top2,1]:=f[top2,1]mod 10007;
end;
dec(top);
f[top2-1,1]:=f[top2,1];
f[top2-1,0]:=f[top2,0];
dec(top2);
end;
begin
yx['*']:=2; yx['+']:=1; yx['(']:=1;
st[0]:='@';
readln(n);
for i:=1 to n do read(s[i]);
for i:=1 to n do
begin
if(s[i]<>'(')and(last<>')')then
begin
inc(top2);
f[top2,1]:=1;
f[top2,0]:=1;
end;
if(s[i]='+')or(s[i]='*')then
begin
while yx[s[i]]<yx[st[top]] do pop;
inc(top);
st[top]:=s[i];
last:='';
end
else
if s[i]=')' then
begin
while st[top]<>'(' do begin pop; end;
dec(top);
last:=')';
end
else
begin
inc(top);
st[top]:=s[i];
last:='';
end;
end;
if last<>')' then
begin
inc(top2);
f[top2,1]:=1;
f[top2,0]:=1;
end;
while top>0 do pop;
write(f[1,0]);
end.
/**************************************************************
Problem: 2303
User: admin
Language: Pascal
Result: Wrong Answer
****************************************************************/