function colcifr(a: integer): integer;
var
s, k: string;
i, j: integer;
begin
i := a;
repeat
str(i mod 10, k);
i := i div 10;
if (pos(k, s) = 0) then
begin
s := concat(s, k);
inc(j);
end;
until (i = 0);
colcifr := j;
end;
function sum(i: integer): integer;
var
a, b: integer;
begin
a := i;
repeat
b := b + a mod 10;
a := a div 10;
until (a = 0);
sum := b;
end;
var
i: integer;
begin
for i := 1000 to 9999 do
if (i mod 2 + i mod 7 + i mod 11 = 0) then
if (colcifr(i) = 2) then
if (sum(i) = 30) then
writeln(i);
end.
8778