def max(a,b); a > b ? a : b; end S = gets.chomp N = S.size dp = Array.new(N + 1){ Array.new(N + 1, 0) } ans = 0 (1 .. N).each do |d| N.times do |l| r = l + d break if r > N if S[l - 1] == S[r - 2] dp[l][r] = dp[l + 1][r - 1] + (l == r - 1 ? 1 : 2) else dp[l][r] = dp[l + 1][r - 1] end ans = max(ans, dp[l][r]) end end puts ans