Source Code
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vl;
typedef pair<ll, ll> pl;
typedef long double ld;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define max(a, b) (a>b ? a : b)
#define min(a, b) (a<b ? a : b)
#define FAST ios::sync_with_stdio(0), cin.tie(0),cout.tie(0)


const int N = int(1e6) + 3;
const int MOD = int(1e9) + 7;

int n;
string s;


int main() {
    FAST;
    //freopen("easy", "r", stdin);
    cin >> n;
    cin >> s;
    if(s[0]==s[n-1]){
        cout << n-1 << endl;
        return 0;
    }
    if(n>=2){
        cout << n-2 << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}
Copy
Pop Pop Mtaylor
GNU G++17
0 ms
840 KB
Accepted