#include #include #include #include std::string manacher(const std::string &str) { int n = 2 * str.size() + 1; std::vector d(n); int c = 0, r = 0; for (int i = 0; i < n; i++) { int i_prime = c - (i - c); if (i < r && i + d[i_prime] < r) { d[i] = d[i_prime]; } else { d[i] = i <= r ? r - i : 0; if ((i + d[i]) % 2 == 1) { d[i]++; } while (i - d[i] - 1 >= 0 && i + d[i] + 1 < n && str[(i - d[i] - 1) / 2] == str[(i + d[i] + 1) / 2]) { d[i] += 2; } if (i + d[i] > r) { c = i; r = i + d[i]; } } } int max_i = 0; for (int i = 0; i < n; i++) { if (d[max_i] < d[i]) { max_i = i; } } return str.substr((max_i - d[max_i]) / 2, d[max_i]); } int main(void) { std::string str; std::cin >> str; std::cout << manacher(str) << std::endl; return 0; }