#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323846
#define mod 1000000007
#define ll long long
#define vi vector<int>
#define ii pair<int, int>
#define pb push_back
#define all(c) (c).begin(), (c).end()
const int N = 1e6;
int n;
string s;
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
cin >> n >> s;
if (s[0] == s[n - 1])
cout << n - 1 << endl;
else {
for (int i = 1; i < n; ++i) {
if (s[0] == s[i - 1] && s[n - 1] == s[i]) {
cout << n - 2 << endl;
return 0;
}
}
}
cout << 0 << endl;
}
Copy