program parentesi2;
Uses sysutils;
{$H+}
const MAXN=10010;
var
N, i, pos, pos1, lungh,totmodipossibili: LongInt;
ST:Ansistring;
E: array[0..MAXN] of char;
E1,stringa1: array[0..MAXN] of char;
indice :array[0..MAXN] of longint;
p:char;
verificabilanciamento:boolean;
function conta (stringa:array of char;id:longint):longint;
begin
write (id,' ',totmodipossibili,' ');
if id=N then
begin
(*leggo e verifico se è bilanciata*)
pos1:=-1;
pos:=-1;
while (pos <N-1) do
begin
pos:=pos+1;
p:=stringa[pos];
if p='{' then
begin
pos1:=pos1+1;
stringa1[pos1]:=p;
indice[pos1]:=pos;
end
else
if ( p='}') then begin if (pos1>=0) and (stringa1[pos1]='{') then pos1:=pos1-1
else begin pos1:=pos1+1; stringa1[pos1]:=p; indice[pos1]:=pos;end;
end;
end;
(*quello che rimane sono parentesi non bilanciate *)
lungh:=pos1+1;
if lungh=0 then verificabilanciamento:=true
else verificabilanciamento:=false;
if verificabilanciamento=true then totmodipossibili:=totmodipossibili+1;
writeln(verificabilanciamento);
end;
writeln(stringa[id-1]);
if stringa[id]='{' then conta(stringa,id+1);
if stringa[id]='}' then conta(stringa,id+1);
if stringa[id]='*' then
begin
stringa[id]:='{' ; conta(stringa,id+1);
stringa[id]:='}' ; conta(stringa,id+1);
stringa[id]:='*' ;
end;
conta:=totmodipossibili;
end;
begin
(*assign(input, 'input.txt'); reset(input);
assign(output, 'output.txt'); rewrite(output);*)
ReadLn(N);
readln(ST);
(*uso un array per memorizzare la posizione iniziale delle parentesi aperte e chiuse nella espressione*)
for i:=0 to N-1 do E[i]:=ST[i+1];
totmodipossibili:=0;
writeln(conta(E,0));
end.
cHJvZ3JhbSBwYXJlbnRlc2kyOwpVc2VzIHN5c3V0aWxzOwp7JEgrfQpjb25zdCBNQVhOPTEwMDEwOwp2YXIKICAgIE4sIGksICBwb3MsIHBvczEsIGx1bmdoLHRvdG1vZGlwb3NzaWJpbGk6IExvbmdJbnQ7CiAgICBTVDpBbnNpc3RyaW5nOwogICAgRTogYXJyYXlbMC4uTUFYTl0gb2YgY2hhcjsKICAgIEUxLHN0cmluZ2ExOiBhcnJheVswLi5NQVhOXSBvZiBjaGFyOwogICAgaW5kaWNlIDphcnJheVswLi5NQVhOXSBvZiBsb25naW50OwogICAgcDpjaGFyOwogICAgdmVyaWZpY2FiaWxhbmNpYW1lbnRvOmJvb2xlYW47CgpmdW5jdGlvbiBjb250YSAoc3RyaW5nYTphcnJheSBvZiBjaGFyO2lkOmxvbmdpbnQpOmxvbmdpbnQ7CgpiZWdpbgogIHdyaXRlIChpZCwnICcsdG90bW9kaXBvc3NpYmlsaSwnICcpOyAKICBpZiBpZD1OIHRoZW4KICAgICAgICAgYmVnaW4KICAgICAgICAgICAoKmxlZ2dvIGUgdmVyaWZpY28gc2Ugw6ggYmlsYW5jaWF0YSopCiAgICAgICAgICAgcG9zMTo9LTE7IAogICAgICAgICAgIHBvczo9LTE7IAogICAgICAgICAgIHdoaWxlIChwb3MgPE4tMSkgIGRvCiAgICAgICAgICAgICAgICBiZWdpbgogICAgICAgICAgICAgICAgICBwb3M6PXBvcysxOwogICAgICAgICAgICAgICAgICBwOj1zdHJpbmdhW3Bvc107CiAgICAgICAgICAgICAgICAgIGlmIHA9J3snIHRoZW4gCiAgICAgICAgICAgICAgICAgICAgICAgICAgYmVnaW4KICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBvczE6PXBvczErMTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHN0cmluZ2ExW3BvczFdOj1wOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaW5kaWNlW3BvczFdOj1wb3M7CiAgICAgICAgICAgICAgICAgICAgICAgICAgZW5kICAgCiAgICAgICAgICAgICAgICAgICAgICAgICBlbHNlCiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKCBwPSd9JykgdGhlbiBiZWdpbiBpZiAocG9zMT49MCkgYW5kIChzdHJpbmdhMVtwb3MxXT0neycpIHRoZW4gcG9zMTo9cG9zMS0xCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGVsc2UgYmVnaW4gcG9zMTo9cG9zMSsxOyBzdHJpbmdhMVtwb3MxXTo9cDsgaW5kaWNlW3BvczFdOj1wb3M7ZW5kOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZW5kOwogICAgICAgICAgICAgIGVuZDsKICAgICAgKCpxdWVsbG8gY2hlIHJpbWFuZSBzb25vIHBhcmVudGVzaSBub24gYmlsYW5jaWF0ZSAqKQogICAgICAgICAgICAgICAgICBsdW5naDo9cG9zMSsxOwogICAgICAgICAgICAgICAgICBpZiBsdW5naD0wIHRoZW4gdmVyaWZpY2FiaWxhbmNpYW1lbnRvOj10cnVlCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZWxzZSB2ZXJpZmljYWJpbGFuY2lhbWVudG86PWZhbHNlOwogICAgICAgICAgICAgICAgICBpZiB2ZXJpZmljYWJpbGFuY2lhbWVudG89dHJ1ZSB0aGVuICB0b3Rtb2RpcG9zc2liaWxpOj10b3Rtb2RpcG9zc2liaWxpKzE7CiAgICAgICAgICAgICAgICAgd3JpdGVsbih2ZXJpZmljYWJpbGFuY2lhbWVudG8pOyAKICAgICAgICBlbmQ7IAogICAgICAgIHdyaXRlbG4oc3RyaW5nYVtpZC0xXSk7IAogICAgICAgIGlmIHN0cmluZ2FbaWRdPSd7JyAgdGhlbiBjb250YShzdHJpbmdhLGlkKzEpOwogICAgICAgIGlmIHN0cmluZ2FbaWRdPSd9JyAgdGhlbiAgY29udGEoc3RyaW5nYSxpZCsxKTsKICAgICAgICBpZiBzdHJpbmdhW2lkXT0nKicgdGhlbiAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICBiZWdpbiAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzdHJpbmdhW2lkXTo9J3snIDsgY29udGEoc3RyaW5nYSxpZCsxKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzdHJpbmdhW2lkXTo9J30nIDsgY29udGEoc3RyaW5nYSxpZCsxKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzdHJpbmdhW2lkXTo9JyonIDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGVuZDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgCmNvbnRhOj10b3Rtb2RpcG9zc2liaWxpOyAKZW5kOwpiZWdpbgogICAgKCphc3NpZ24oaW5wdXQsICAnaW5wdXQudHh0Jyk7ICByZXNldChpbnB1dCk7CiAgICBhc3NpZ24ob3V0cHV0LCAnb3V0cHV0LnR4dCcpOyByZXdyaXRlKG91dHB1dCk7KikKICAgIFJlYWRMbihOKTsKICAgIHJlYWRsbihTVCk7CiAgICAoKnVzbyB1biBhcnJheSBwZXIgbWVtb3JpenphcmUgbGEgcG9zaXppb25lIGluaXppYWxlIGRlbGxlIHBhcmVudGVzaSBhcGVydGUgZSBjaGl1c2UgbmVsbGEgZXNwcmVzc2lvbmUqKQogICAgZm9yIGk6PTAgdG8gTi0xIGRvIEVbaV06PVNUW2krMV07IAogICAgdG90bW9kaXBvc3NpYmlsaTo9MDsKICAgIHdyaXRlbG4oY29udGEoRSwwKSk7CmVuZC4K