# -*- coding: utf-8 -*- W = 'w' readlines.each { |s| ans = {} s.size.times { |i| if s[i] != W && s[i+1] == W j = i t = '' while j >= 0 && s[j] != W t = s[j] + t j = j-1 end j = i+1 while j < s.size && s[j] == W j += 1 end ans[j-i] = [] if ans[j-i].nil? ans[j-i] << t end } 1000.downto(0) { |i| if ans[i] puts ans[i] break end } }