#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
#include <iomanip>
#include <fstream>
#include <chrono>
using namespace std;
int main()
{
int n;
cin >> n;
string input;
cin >> input;
if (n == 1)
{
cout << 0 << endl;
return 0;
}
char first = input[0];
char last = input[n - 1];
int i;
for (i = 1; i < n - 1; i++)
{
for (int j = 0; (j + i) < n; j++)
{
if (input[j] == first && input[j + i] == last)
{
cout << n - i - 1 << endl;
return 0;
}
}
}
cout << 0 << endl;
return 0;
}
Copy