Source Code
#include <bits/stdc++.h>
#define ll long long
#define mk make_pair
#define pb push_back
using namespace std;
ll mod = 1000000007;

void solve(){
    int n ; cin >> n;
    string s;
    cin >> s;
    if(s[0] == s[n-1]){
        cout << n-1 ;
    }
    else{
        cout << max(0 , n - 2) ;
    }


}
int main(){
    int t = 1 ;
    //cin >> t ;
    while(t--){
        solve();
    }
    return 0;
}
Copy
Pop Pop Apple
GNU G++17
2 ms
880 KB
Accepted