n = gets.chomp tot = 2 tot2 = 1 qq = [3,1,1,1,3,1,3,1,4,3] qq2 = [3,2,2,2,3,2,3,2,4,3] for c in n.split('') tot += qq[c.ord - 48] tot2 += qq2[c.ord - 48] end puts [tot, tot2].min