hist = [20104,20063,19892,20011,19874,20199,19898,20163,19956,19841] str = gets.chars before = after = '' 0.upto(9) { |c| cnt = str.count(c.to_s) if hist[c] < cnt before = c elsif hist[c] > cnt after = c end } puts "#{before} #{after}"