問題一覧 > 通常問題

No.1617 Palindrome Removal

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 187
作問者 : だれ / テスター : nok0 yuto1115
お気に入りにしたユーザー ProblemId : 6553 / 自分の提出
問題文最終更新日: 2026-04-28 14:20:43
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Show the original
問題文一行コンテスト (順位表) の他の問題:

Problem Statement

Among the strings that are not palindromes and can be obtained by removing an even number of characters from the string $S$, find the length of the longest one.

Input

$S$

  • $1\leq |S|\leq 10^6$
  • $S$ consists of lowercase English letters

Output

Output the answer on one line. If no non-palindromic string can be obtained, output -1 instead.

Sample

Sample 1
Input
aaabbbaaa
Output
7

For example, removing the a at position $3$ and the b at position $4$ gives aabbaaa, which is not a palindrome.

Sample 2
Input
abc
Output
3

The string is not a palindrome to begin with.

Sample 3
Input
aaaa
Output
0

The empty string is not considered a palindrome.

Sample 4
Input
z
Output
-1

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。