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