var x,s,p:integer;beginp:=1;while s<300 do beginreadln(x);if x mod 3=0 then p:=p*x;s:=s+x;end;if p<>1 then writeln(p) else writeln('0');end.