s = gets.strip len_max = 0 (1...s.length).each do |i| len = 1 (1...s.length).each do |j| break if i - j < 0 || i + j >= s.length if s[i - j] == s[i + j] len += 2 else break end end len_max = [len_max, len].max end # p len_max (1...s.length).each do |i| len = 0 (1...s.length).each do |j| break if i - j + 1 < 0 || i + j >= s.length if s[i - j + 1] == s[i + j] len += 2 else break end end len_max = [len_max, len].max end p len_max