#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <string>
#include <cstring>
#include <iterator>
#include <random>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;
const ll dim = 5*1e3+7;
//const ll mod = 1e9 + 7;
const ll inf = 1e18 + 77;
#define endl "\n"
#define fi first
#define pb push_back
#define se second
#define vll vector<ll>
ll n, m;
pll a[dim];
ll b[dim];
int main() {
ll k, t, u0, v0;
string s;
cin>>n;
cin>>s;
ll ans=0;
for(int i=1; i<n; i++){
if(s[i]==s[i-1]){
for(int j=i+1; i<n; i++){
if(s[j]!=s[i]){
ans+=abs(j-i);
swap(s[j], s[i]);
break;
}
}
}
}
// cout<<s<<endl;
cout<<ans<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |