use integer; @a=(0)x20; $/=$";$n=<>; map{ $r=$n%$_; $n/=$_; $_+=$_>=$r for@a[20-$_..19]; $a[20-$_]=$r; }1..20; $b[$a[$_]]=$_ for 0..19; $\=$\*(20-$_)+$b[$_]-grep$_<$b[$'],@b[0..$_-//]for 0..19; print;