s = gets.chomp puts s.scan(/([^w]+)(w+)/) .group_by{|a| a[1]} .max[1] .map{|a| a[0]} rescue ""