gets p (0..4e4).map{|n|*d=0 30.times{d<<(0..2).map{|x|d[~(n>>5*x&31)]||$$}.min+1} eval$_.gsub /\d+/,'+d[\0]'}.min