class Yukicoder def initialize s = gets.chomp word = "" temp = "" list = Hash.new(0) w_count = 0 s.sub!(/^w+/,'') s.chars do |ch| if ch == 'w' if w_count == 0 temp = word.dup end w_count += 1 list[temp] += 1 word = "" else w_count = 0 word += ch end end list = list.sort_by{|k,v| -v}.to_h max_val = list.first[1] puts list.select{|k,v| max_val == v}.keys end end Yukicoder.new