program Project1;
{$APPTYPE CONSOLE}
uses
SysUtils;
var
s: string;
function IsVar(s: string): Boolean;
var
l, i: Integer;
begin
Result:=True;
l:=Length(s);
if l<2 then
begin
Result:=False;
Exit
end;
if not (s[1] in ['A'..'G']) then
begin
Result:=False;
Exit
end;
for i:=2 to ldo
if not (s in ['0'..'9']) then
begin
Result:=False;
Exit
end
end;
function FindOp(s: string): Integer;
var
Count: Integer;
i: Integer;
l: Integer;
begin
l:=Length(s);
i:=0;
Count:=0;
repeat
Inc(i);
if s='(' then
Inc(Count)
else
if s=')' then
Dec(Count)
until ((Count=0) and (s in ['+', '-', '*', '/'])) or (i>l);
if i>l then
Result:=0
else
Result:=i
end;
function Hahaha(s: string): Boolean;
var
p, l: Integer;
s1, s2: string;
begin
l:=Length(s);
if (s[1]='(') and (s[l]=')') then
begin
s1:=Copy(s, 2, l-2);
Result:=Hahaha(s1)
end
else
begin
p:=FindOp(s);
if p=0 then
Result:=IsVar(s)
else
begin
s1:=Copy(s, 1, p-1);
s2:=Copy(s, p+1, l-p);
Result:=Hahaha(s1) and Hahaha(s2)
end
end
end;
begin
Write('Input s: ');
ReadLn(s);
while s<>''do
begin
if Hahaha(UpperCase(s)) then
WriteLn('1')
else
WriteLn('0');
Write('Input s: ');
ReadLn(s)
end
end.