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

#define IO ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    IO
    int n, ans = 0;
    string s, tmp;
    cin >> n >> s;
    tmp = s[0] + s[n - 1];
    if (s.find(tmp) != -1) {
        cout << ans;
    } else {
        if (s[0] == s[n - 1]) {
            cout << n - 1;
        } else {
            cout << n - 2;
        }
    }
    return 0;
}
Copy
Pop Pop NadaAdel
GNU G++17
1 ms
868 KB
Accepted