import std.conv, std.functional, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.container, std.math, std.numeric, std.range, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; } int readInt() { return readToken.to!int; } long readLong() { return readToken.to!long; } real readReal() { return readToken.to!real; } bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } } bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } } int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; } int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); } int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); } enum long[] P = [1000000007, 1000000009]; enum LIM = 2 * 10^^5; int N; string S; void main() { auto BASE = new long[P.length]; BASE[0] = 314159265L; foreach (h; 1 .. P.length) { BASE[h] = (BASE[h - 1] * 123456789L) % 999999937L; } auto BB = new long[][](P.length, LIM + 1); foreach (h; 0 .. P.length) { BB[h][0] = 1; foreach (i; 0 .. LIM) { BB[h][i + 1] = (BB[h][i] * BASE[h]) % P[h]; } } try { for (; ; ) { S = readToken(); N = cast(int)(S.length); auto sum0 = new long[][](P.length, N + 1); auto sum1 = new long[][](P.length, N + 1); foreach (h; 0 .. P.length) { foreach (i; 0 .. N) { sum0[h][i + 1] = (sum0[h][i] + S[i] * BB[h][i]) % P[h]; sum1[h][i + 1] = (sum1[h][i] + S[i] * BB[h][N - i]) % P[h]; } } int calc(int l, int r) { int lo = 0, hi = min(l + 1, N - r) + 1; for (; lo + 1 < hi; ) { const mid = (lo + hi) / 2; bool ok = true; foreach (h; 0 .. P.length) { const tmpL = (sum0[h][l + 1] - sum0[h][l + 1 - mid]) * BB[h][N - r]; const tmpR = (sum1[h][r + mid] - sum1[h][r]) * BB[h][l]; if ((tmpL - tmpR) % P[h] != 0) { ok = false; break; } } (ok ? lo : hi) = mid; } debug { writeln("calc ", l, " ", r, " = ", lo); } return lo; } int ans; foreach (i; 0 .. N) { foreach (s; 0 .. 2) { if (i + s < N) { const int a = calc(i, i + s); chmax(ans, 2 * a - 1 + s - 1); if (0 <= i - a) { chmax(ans, 2 * a - 1 + s + 2 * calc(i - a - 1, i + s + a)); } if (i + s + a < N) { chmax(ans, 2 * a - 1 + s + 2 * calc(i - a, i + s + a + 1)); } } } } writeln(ans); } } catch (EOFException e) { } }