{$B+}
program sdfjh;
uses crt;
var inf:text;
    b:char;
    error:boolean;

procedure vvodvhfile(var f:text);
var ior:integer;   {IOResult}
    adress:string;
begin
{$I-}
repeat
 writeln('vvedite nazvanie vhodnogo faila:');
 readln(adress);
 assign(f,adress);
 reset(f);
 ior:=ioresult;
 if (ior<>0) or (adress='') then writeln('can''t open file! try adress again!');
until (ior=0) and (adress<>'');
{$I+}
end;

function virag(var inf:text):boolean;
var b:char;
    i:integer;
begin
read(inf,b);
while (b='(') or (b=')') or (b=',') do read(inf,b);
if not(eof(inf) or eoln(inf)) then
 if (b='t') then
 begin
  virag:=true;
  for i:=1 to 3 do read(inf,b);
 end
 else
  if b='f' then
  begin
   virag:=false;
   for i:=1 to 4 do read(inf,b);
  end
  else
   if b='o' then
   begin
    read(inf,b);
    virag:=virag(inf) or virag(inf);
   end
   else
    if b='a' then
    begin
     for i:=1 to 2 do read(inf,b);
     virag:=virag(inf) and virag(inf);
    end
    else
     if b='n' then
     begin
      for i:=1 to 2 do read(inf,b);
      virag:=not(virag(inf))
     end;
end;

procedure check(var f:text; var error:boolean);
var b:char;
    i:integer;
begin
error:=false;
repeat
 read(inf,b);
 while (b='(') or (b=')') or (b=',') do read(inf,b);
 if b='n' then
  for i:=1 to 2 do read(inf,b)
 else
  if b='o' then read(inf,b)
  else
   if b='a' then
    for i:=1 to 2 do read(inf,b)
   else
    if b='t' then
     for i:=1 to 3 do read(inf,b)
    else
     if b='f' then
      for i:=1 to 4 do read(inf,b)
     else error:=true;
until eoln(f) or error;
reset(f);
end;

begin
clrscr;
vvodvhfile(inf);
check(inf,error);
if not(error) then
 writeln(virag(inf))
else writeln('Saaaaavsem oshibka v postroenii faila');
readkey;
end.