h=Hash[0,1,1,0,2,0,3,0,4,1,5,0,6,1,7,0,8,2,9,1] a=gets.chomp.chars p [a.inject(0){|s,c|s+h[c.to_i]+2}+1,a.inject(0){|s,c|s+h[c.to_i]*2+1}+2].min