import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop; void main() { auto S = readln.chomp; if (S.length % 2 == 1) { if (is_onaji(S)) { writeln(-1); } else if (is_kaibun(S)) { auto mid = S.length.to!int/2; if (S[mid] != S.front && is_onaji(S[0..mid] ~ S[mid+1..$])) { writeln(-1); } else { writeln(S.length.to!int - 2); } } else { writeln(S.length); } } else { if (is_onaji(S) ) { writeln(0); } else if (is_kaibun(S)) { writeln(S.length.to!int - 2); } else { writeln(S.length); } } } bool is_kaibun(string S) { foreach (i; 0..S.length.to!int/2) { if (S[i] != S[S.length.to!int-i-1]) return false; } return true; } bool is_onaji(string S) { foreach (i; 1..S.length) if (S[i] != S.front) return false; return true; }