$c={} def f(x,y,z) $c[[x,y,z]]||=x>y ?f(f(x-5,y,z),f(y-5,z,x),f(z-5,x,y)):z end puts f(*split.map{|n|n.to_i})while gets