var s,n:integer;
begin
repeat
readln(n);
if (n mod 3=0) and (n<10) then s:=s+n;
until n=0;
writeln('S=',s);
end.
var s,n:integer;
begin
repeat
readln(n);
if (n mod 3=0) and (n<10) then s:=s+n;
until n=0;
writeln('S=',s);
end.