mapping = Struct.new(:rmin, :rmax) str = gets.strip n = str.length (n - 2).downto(0) do |i| 0.upto(n - i - 1) do |j| nstr = str[j, i + 1] find = false ((i + 1) / 2).times do |k| if nstr[k] != nstr[i - k] find = true break end end if !find puts nstr.length exit end end end