#include <iostream>
#include <string>
using namespace std;
int main(){
double n;
string binary;
cin>>n;
cin>>binary;
int count=0;
char last =binary[n-1];
char first=binary[0];
int flag=0;
for (int i=0;i<n;i++){
if (binary[i]==first && binary[i+1]==last)
{
flag=1;
for (int f=0;f<i;f++) count++ ;
for (int l=n-1;l>i+1;l--) count++;
}
if (binary[i]==first && binary[i+1]==last)
break;
}
int 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