var
n, n1, c : integer;
function sled(n:integer): integer;
var a : array [1..4] of integer;
i, j, x : integer;
begin
for i:=1 to 4 do
begin
a[i]:=n mod 10;
n:=n div 10
end;
for i:=1 to 3 do
for j:=1 to 4-i do
if a[j]>a[j+1] then begin x:=a[j]; a[j]:=a[j+1]; a[j+1]:=x end;
sled:=(a[4]-a[1])*999+(a[3]-a[2])*90
end;
begin
assign(input,'input.txt'); reset(input);
assign(output,'output.txt'); rewrite(output);
read(n);
c:=0; n1:=sled(n);
while n<>n1 do
begin
c:=c+1;
n:=n1;
n1:=sled(n)
end;
writeln(n);
write(c)
end.
n, n1, c : integer;
function sled(n:integer): integer;
var a : array [1..4] of integer;
i, j, x : integer;
begin
for i:=1 to 4 do
begin
a[i]:=n mod 10;
n:=n div 10
end;
for i:=1 to 3 do
for j:=1 to 4-i do
if a[j]>a[j+1] then begin x:=a[j]; a[j]:=a[j+1]; a[j+1]:=x end;
sled:=(a[4]-a[1])*999+(a[3]-a[2])*90
end;
begin
assign(input,'input.txt'); reset(input);
assign(output,'output.txt'); rewrite(output);
read(n);
c:=0; n1:=sled(n);
while n<>n1 do
begin
c:=c+1;
n:=n1;
n1:=sled(n)
end;
writeln(n);
write(c)
end.