program parentesi2;
Uses sysutils;
{$H+}
const MAXN=10010;
var
N, i, pos, pos1, lungh,totmodipossibili,tot: 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;
procedure conta (stringa:array of char;id:longint);
begin
write(stringa[id]); ;
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;
end;
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;
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; tot:=0;
conta(E,0);
writeln(totmodipossibili);
end.
cHJvZ3JhbSBwYXJlbnRlc2kyOwpVc2VzIHN5c3V0aWxzOwp7JEgrfQpjb25zdCBNQVhOPTEwMDEwOwp2YXIKICAgIE4sIGksICBwb3MsIHBvczEsIGx1bmdoLHRvdG1vZGlwb3NzaWJpbGksdG90OiBMb25nSW50OwogICAgU1Q6QW5zaXN0cmluZzsKICAgIEU6IGFycmF5WzAuLk1BWE5dIG9mIGNoYXI7CiAgICBFMSxzdHJpbmdhMTogYXJyYXlbMC4uTUFYTl0gb2YgY2hhcjsKICAgIGluZGljZSA6YXJyYXlbMC4uTUFYTl0gb2YgbG9uZ2ludDsKICAgIHA6Y2hhcjsKICAgIHZlcmlmaWNhYmlsYW5jaWFtZW50bzpib29sZWFuOwoKcHJvY2VkdXJlIGNvbnRhIChzdHJpbmdhOmFycmF5IG9mIGNoYXI7aWQ6bG9uZ2ludCk7CgpiZWdpbgogd3JpdGUoc3RyaW5nYVtpZF0pOyAgICA7CiAgaWYgaWQ9TiB0aGVuCiAgICAgICAgIGJlZ2luCiAgICAgICAgICAgKCpsZWdnbyBlIHZlcmlmaWNvIHNlIMOoIGJpbGFuY2lhdGEqKQogICAgICAgICAgIHBvczE6PS0xOyAKICAgICAgICAgICBwb3M6PS0xOyAKICAgICAgICAgICB3aGlsZSAocG9zIDxOLTEpICBkbwogICAgICAgICAgICAgICAgYmVnaW4KICAgICAgICAgICAgICAgICAgcG9zOj1wb3MrMTsKICAgICAgICAgICAgICAgICAgcDo9c3RyaW5nYVtwb3NdOwogICAgICAgICAgICAgICAgICBpZiBwPSd7JyB0aGVuIAogICAgICAgICAgICAgICAgICAgICAgICAgIGJlZ2luCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBwb3MxOj1wb3MxKzE7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzdHJpbmdhMVtwb3MxXTo9cDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGluZGljZVtwb3MxXTo9cG9zOwogICAgICAgICAgICAgICAgICAgICAgICAgIGVuZCAgIAogICAgICAgICAgICAgICAgICAgICAgICAgZWxzZQogICAgICAgICAgICAgICAgICAgICAgICAgIGlmICggcD0nfScpIHRoZW4gYmVnaW4gaWYgKHBvczE+PTApIGFuZCAoc3RyaW5nYTFbcG9zMV09J3snKSB0aGVuIHBvczE6PXBvczEtMQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBlbHNlIGJlZ2luIHBvczE6PXBvczErMTsgc3RyaW5nYTFbcG9zMV06PXA7IGluZGljZVtwb3MxXTo9cG9zO2VuZDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGVuZDsKICAgICAgICAgICAgICBlbmQ7CiAgICAgICAgICAgICAgCiAgICAgICgqcXVlbGxvIGNoZSByaW1hbmUgc29ubyBwYXJlbnRlc2kgbm9uIGJpbGFuY2lhdGUgKikKICAgICAgICAgICAgICAgICAgbHVuZ2g6PXBvczErMTsKICAgICAgICAgICAgICAgICAgaWYgbHVuZ2g9MCB0aGVuIHZlcmlmaWNhYmlsYW5jaWFtZW50bzo9dHJ1ZQogICAgICAgICAgICAgICAgICAgICAgICAgICAgIGVsc2UgdmVyaWZpY2FiaWxhbmNpYW1lbnRvOj1mYWxzZTsKICAgICAgICAgICAgICAgICAgaWYgdmVyaWZpY2FiaWxhbmNpYW1lbnRvPXRydWUgdGhlbiAgdG90bW9kaXBvc3NpYmlsaTo9dG90bW9kaXBvc3NpYmlsaSsxOwogICAgICAgICAgICAgICAgICAgCiAgICAgICAgZW5kOyAKICAgICAgCiAgICAgICAgaWYgc3RyaW5nYVtpZF09J3snICB0aGVuIGNvbnRhKHN0cmluZ2EsaWQrMSk7CiAgICAgICAgaWYgc3RyaW5nYVtpZF09J30nICB0aGVuICBjb250YShzdHJpbmdhLGlkKzEpOwogICAgICAgIGlmIHN0cmluZ2FbaWRdPScqJyB0aGVuIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYmVnaW4KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzdHJpbmdhW2lkXTo9J3snIDsgY29udGEoc3RyaW5nYSxpZCsxKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzdHJpbmdhW2lkXTo9J30nIDsgY29udGEoc3RyaW5nYSxpZCsxKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzdHJpbmdhW2lkXTo9JyonIDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZW5kOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAKZW5kOwpiZWdpbgogICAgKCphc3NpZ24oaW5wdXQsICAnaW5wdXQudHh0Jyk7ICByZXNldChpbnB1dCk7CiAgICBhc3NpZ24ob3V0cHV0LCAnb3V0cHV0LnR4dCcpOyByZXdyaXRlKG91dHB1dCk7KikKICAgIFJlYWRMbihOKTsKICAgIHJlYWRsbihTVCk7CiAgICAoKnVzbyB1biBhcnJheSBwZXIgbWVtb3JpenphcmUgbGEgcG9zaXppb25lIGluaXppYWxlIGRlbGxlIHBhcmVudGVzaSBhcGVydGUgZSBjaGl1c2UgbmVsbGEgZXNwcmVzc2lvbmUqKQogICAgZm9yIGk6PTAgdG8gTi0xIGRvIEVbaV06PVNUW2krMV07IAogICAgdG90bW9kaXBvc3NpYmlsaTo9MDsgdG90Oj0wOwogICAgY29udGEoRSwwKTsKICAgIHdyaXRlbG4odG90bW9kaXBvc3NpYmlsaSk7CmVuZC4K