- $\textbf{for} \ \forall i \in [1, n]$ 枚举每个中心点
- 二分回文半径 $r$,判断 $[i-mid, i-1]$ 和 $[i+1, i+mid]$ 是否满足回文?
- $\textbf{if}$ 满足回文性质,扩大半径
- $\textbf{else}$ 减少半径
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <bitset>
#include <assert.h>
#include <unordered_map>
using namespace std;
typedef long long ll;
#define Cmp(a, b) memcmp(a, b, sizeof(b))
#define Cpy(a, b) memcpy(a, b, sizeof(b))
#define Set(a, v) memset(a, v, sizeof(a))
#define debug(x) cout << #x << ": " << x << endl
#define _forS(i, l, r) for(set<int>::iterator i = (l); i != (r); i++)
#define _rep(i, l, r) for(int i = (l); i <= (r); i++)
#define _for(i, l, r) for(int i = (l); i < (r); i++)
#define _forDown(i, l, r) for(int i = (l); i >= r; i--)
#define debug_(ch, i) printf(#ch"[%d]: %d\n", i, ch[i])
#define debug_m(mp, p) printf(#mp"[%d]: %d\n", p->first, p->second)
#define debugS(str) cout << "dbg: " << str << endl;
#define debugArr(arr, x, y) _for(i, 0, x) { _for(j, 0, y) printf("%c", arr[i][j]); printf("\n"); }
#define _forPlus(i, l, d, r) for(int i = (l); i + d < (r); i++)
#define lowbit(i) (i & (-i))
#define MPR(a, b) make_pair(a, b)
pair<int, int> crack(int n) {
int st = sqrt(n);
int fac = n / st;
while (n % st) {
st += 1;
fac = n / st;
}
return make_pair(st, fac);
}
inline ll qpow(ll a, int n) {
ll ans = 1;
for(; n; n >>= 1) {
if(n & 1) ans *= 1ll * a;
a *= a;
}
return ans;
}
template <class T>
inline bool chmax(T& a, T b) {
if(a < b) {
a = b;
return true;
}
return false;
}
ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a % b);
}
ll ksc(ll a, ll b, ll mod) {
ll ans = 0;
for(; b; b >>= 1) {
if (b & 1) ans = (ans + a) % mod;
a = (a * 2) % mod;
}
return ans;
}
ll ksm(ll a, ll b, ll mod) {
ll ans = 1 % mod;
a %= mod;
for(; b; b >>= 1) {
if (b & 1) ans = ksc(ans, a, mod);
a = ksc(a, a, mod);
}
return ans;
}
template <class T>
inline bool chmin(T& a, T b) {
if(a > b) {
a = b;
return true;
}
return false;
}
template<class T>
bool lexSmaller(vector<T> a, vector<T> b) {
int n = a.size(), m = b.size();
int i;
for(i = 0; i < n && i < m; i++) {
if (a[i] < b[i]) return true;
else if (b[i] < a[i]) return false;
}
return (i == n && i < m);
}
// ============================================================== //
typedef unsigned long long ull;
const int maxn = 2000000 + 10, P = 131;
char str[maxn];
int n;
ull hl[maxn], hr[maxn], p[maxn];
void prework() {
for (int i = n*2; i >= 1; i -= 2) {
str[i] = str[i/2];
str[i-1] = 'z' + 1;
}
n *= 2;
p[0] = 1;
for (int i = 1, j = n; i <= n; i++, j--) {
hl[i] = hl[i-1] * P + str[i] - 'a' + 1;
hr[i] = hr[i-1] * P + str[j] - 'a' + 1;
p[i] = p[i-1] * P;
}
}
ull get(const ull h[], int l, int r) {
return h[r] - h[l-1] * p[r-l+1];
}
void solve() {
int ans = 0;
for (int i = 1; i <= n; i++) {
int l = 0, r = min(i-1, n-i);
while (l < r) {
int mid = (l + r + 1) >> 1;
if (get(hl, i-mid, i-1) != get(hr, n+1-(i+mid), n+1-(i+1))) r = mid - 1;
else l = mid;
}
// ans is l
if (str[i-l] <= 'z') ans = max(ans, l+1);
else ans = max(ans, l);
}
printf("%d\n", ans);
}
int main() {
freopen("input.txt", "r", stdin);
int kase = 0;
while (scanf("%s", str+1) && str[1] != 'E') {
n = strlen(str+1);
printf("Case %d: ", ++kase);
// prework
prework();
// then solve
solve();
}
}