Source Code
#include <bits/stdc++.h>
using namespace std;
#define oo 1000000010
#define mod 1000000007
const int N = 100010;

int n ;
char s[N];


int main(){
	scanf("%d",&n);
	scanf("%s",s);
	if(s[0] == s[n - 1])
		cout << n - 1 << endl;
	else
		cout << n - 2 << endl;
	return 0;
}
Copy
Pop Pop Kilani
GNU G++17
1 ms
732 KB
Accepted