/* -*- coding: utf-8 -*- * * 1617.cc: No.1617 Palindrome Removal - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 1000000; /* typedef */ /* global variables */ char s[MAX_N + 4]; int cs[26]; /* subroutines */ bool palindrome(int n, char s[]) { for (int i = 0, j = n - 1; i < j; i++, j--) if (s[i] != s[j]) return false; return true; } /* main */ int main() { scanf("%s", s); int n = strlen(s); if (! palindrome(n, s)) { printf("%d\n", n); return 0; } int k = 0; for (int i = 0; s[i]; i++) if (cs[s[i] - 'a']++ == 0) k++; if (k == 1) printf("%d\n", (n & 1) ? -1 : 0); else printf("%d\n", n - 2); return 0; }