int nxt[maxn]; voidinit_nxt(char *s){ int k = 0, n = strlen(s + 1); nxt[1] = 0; for (int i = 2; i <= n; ++i) { while (k && s[k + 1] != s[i]) k = nxt[k]; if (s[k + 1] == s[i]) ++k; nxt[i] = k; } }
structEdge { int to, next; } e[maxn]; int c1, head[maxn]; inlinevoidadd_edge(int u, int v){ e[c1].to = v; e[c1].next = head[u]; head[u] = c1++; } int n; char s[maxn];
int l[maxn], r[maxn], Max; voiddel(int x){ r[l[x]] = r[x]; l[r[x]] = l[x]; Max = max(Max, r[x] - l[x]); }
voiddfs(int u, int t){ if (u) del(u); for (int i = head[u]; ~i; i = e[i].next) { int v = e[i].to; if (v == t) continue; dfs(e[i].to, t); } }
intmain(){ fill(head, head + maxn, -1); ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
cin >> s + 1; n = strlen(s + 1); init_nxt(s); for (int i = 1; i <= n; ++i) add_edge(nxt[i], i); vector<int> A; for (int i = n; i; i = nxt[i]) A.push_back(i); A.push_back(0); reverse(A.begin(), A.end()); int ans = n; for (int i = 1; i <= n; ++i) l[i] = i - 1, r[i] = i + 1; for (int i = 1; i < A.size(); ++i) { dfs(A[i - 1], A[i]); if (Max <= A[i]) ans = min(ans, A[i]); } cout << ans << "\n"; return0; }