Source Code
#include <iostream>
#include <string>
using namespace std;
int main(){
int n;
string binary;
cin>>n;
cin>>binary;
int count=0;
char last =binary[n-1];
char first=binary[0];

for (int i=0;i<n;i++){

if (binary[i]==first && binary[i+1]==last)
{
        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;

}
cout<<count;
}
Copy
Pop Pop Reem-Assi
GNU G++17
1 ms
440 KB
Wrong Answer