#include <iostream>
#include <string>
using namespace std;
int main(){
long long n;
string binary;
cin>>n;
cin>>binary;
long long count=0;
char last =binary[n-1];
char first=binary[0];
int flag=0;
for (long long i=0;i<n;i++){
if (binary[i]==first && binary[i+1]==last)
{
flag=1;
for (long long f=0;f<i;f++) count++ ;
for (long long l=n-1;l>i+1;l--) count++;
}
if (binary[i]==first && binary[i+1]==last)
break;
}
long long y=2;
while (flag==0){
for (int i=0;i<n;i++){
if (binary[i]==first && binary[i+y]==last)
{
flag=1;
for (int f=0;f<i;f++) count++ ;
for (int l=n-1;l>i+y;l--) count++;
}
if (binary[i]==first && binary[i+y]==last)
break;
}
y++;
}
cout<<count;
}
Copy