Var
i, s, k, n: integer;
begin
for i := 1000 to 9999 do begin
n := i;
s := 0;
while n > 0 do begin
s := s + (n mod 10) * (n mod 10);
n := n div 10;
end;
if (s mod 2 = 0) or (s mod 3 = 0) then begin
k := k + 1;
writeln(i, ' ', s);
end;
end;
writeln(k);
end.