Source Code
#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;
		return 0;
	}

	cout << n - 2 << endl;
}
Copy
Pop Pop omarthejuiceboi
GNU G++17
3 ms
856 KB
Accepted