#include #define MAX 500000 int main() { int count, res = -1; char str[MAX]; int pom = 1; scanf("%d ", &count); fgets(str, MAX, stdin); for(int i = 0; i < count; i++){ for(int j = i; j < count - pom; j++){ if(str[j] != str[count - pom]){ pom = 1; break; } pom++; if(j == count - pom || j == count - pom - 1){ res = i; } } if(res > -1){ break; } } if(res == -1){ res = count - 1; } printf("%d\n", res); return 0; }