#include using ll = long long; std::mt19937 mt{std::random_device{}()}; template class RollingHash { public: RollingHash(const C& s) : pow1(s.size() + 1, 1), pow2(s.size() + 1, 1), hash1(s.size() + 1, 0), hash2(s.size() + 1, 0), base1{std::uniform_int_distribution{2, mod1 - 1}(mt)}, base2{std::uniform_int_distribution{2, mod2 - 1}(mt)} { for (std::size_t i = 1; i <= s.size(); i++) { pow1[i] = (pow1[i - 1] * base1) % mod1, pow2[i] = (pow2[i - 1] * base2) % mod2, hash1[i] = (hash1[i - 1] * base1 + (ll)s[i - 1]) % mod1, hash2[i] = (hash2[i - 1] * base2 + (ll)s[i - 1]) % mod2; } } std::pair getHash(const std::size_t l, const std::size_t r) const { return {(mod1 + (hash1[r] - hash1[l] * pow1[r - l]) % mod1) % mod1, (mod2 + (hash2[r] - hash2[l] * pow2[r - l]) % mod2) % mod2}; } private: std::vector pow1, pow2, hash1, hash2; const ll base1, base2; }; std::vector Manacher(const std::string& S) { std::vector R(S.size()); for (int i = 0, k = 1, j = 0; i < S.size(); i += k, j -= k, k = 1) { while (i >= j and i + j < S.size() and S[i - j] == S[i + j]) { ++j; } R[i] = j; while (i >= k and i + k < S.size() and k + R[i - k] < j) { R[i + k] = R[i - k], ++k; } } return R; } int main() { std::string s; std::cin >> s; const int N = s.size(); std::string S; for (const char c : s) { S.push_back(c), S.push_back('$'); } S.pop_back(); std::string R = S; std::reverse(R.begin(), R.end()); const std::string T = S + "#" + R; RollingHash<> hash(T); const auto m = Manacher(S); int max = 0; for (int i = 0; i < S.size(); i++) { if (i - m[i] == -1 and i + m[i] == S.size()) { return std::cout << N - 1 << std::endl, 0; } if (i - m[i] == -1 or i + m[i] == S.size()) { max = std::max(max, i % 2 == 1 ? m[i] / 2 * 2 : (m[i] + 1) / 2 + (m[i] - 1) / 2); continue; } { int inf = -1, sup = std::min((int)S.size() - (i + m[i]) - 1, i - m[i] + 2); while (sup - inf > 1) { const int mid = (inf + sup) / 2; const auto l = hash.getHash(2 * S.size() - i + m[i], 2 * S.size() - i + m[i] + mid); const auto r = hash.getHash(i + m[i] + 2, i + m[i] + mid + 2); (l == r ? inf : sup) = mid; } const int len = m[i] + inf; max = std::max(max, i % 2 == 1 ? len / 2 * 2 : (len + 1) / 2 + (len - 1) / 2); } { int inf = -1, sup = std::min((int)S.size() - (i + m[i]) + 1, i - m[i]); while (sup - inf > 1) { const int mid = (inf + sup) / 2; const auto l = hash.getHash(2 * S.size() - i + m[i] + 2, 2 * S.size() - i + m[i] + 2 + mid); const auto r = hash.getHash(i + m[i], i + m[i] + mid); (l == r ? inf : sup) = mid; } const int len = m[i] + inf; max = std::max(max, i % 2 == 1 ? len / 2 * 2 : (len + 1) / 2 + (len - 1) / 2); } } std::cout << max << std::endl; return 0; }