def f(n)([1]+(2..n).map{|i|n%i==0?f(n/i)+n/100+n/10%10+n%10:0}).max end while n=gets p f(n.to_i) end