#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
#define pb push_back
#define int long long
#define no "NO\n"
#define yes "YES\n"
#define ew "\n"
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define float long double
#define len(x) (int)x.size()
#define macvin \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
using pii = pair<int, int>;
using ld = long double;
const int N = 2e6 + 7;
const int mod = 1e9 + 7;
const int inf = 1e18 + 7;
const int hh = 1e2 + 70;
const int MAX = 200007;
const int maxn = 1e6 + 7;
int n, q;
int used[N];
int calc(string s, string xx)
{
int swaps = 0;
vector<int> ans;
for (int i = 0; i < n; i++)
{
if (s[i] != xx[i])
{
ans.pb(i);
}
}
for (int i = 0; i + 1 < ans.size(); i += 2)
{
swaps += ans[i + 1] - ans[i];
}
return swaps;
}
void iamgoingto10of10()
{
cin >> n;
string s;
cin >> s;
int cntr = count(all(s), 'R');
int cntg = count(all(s), 'G');
int cnty = count(all(s), 'Y');
if (abs(cntr - cntg) > 1 || abs(cnty - cntr) > 1 || abs(cntg - cnty) > 1)
{
cout << -1;
return;
}
string x1, x2;
for (int i = 0; i < n; i++)
{
if (i % 3 == 0)
{
x1 += 'R', x2 += 'G';
}
else if (i % 3 == 1)
{
x1 += 'G', x2 += 'Y';
}
else
{
x1 += 'Y', x2 += 'R';
}
}
cout << min(calc(s, x1), calc(s, x2));
}
signed main()
{
macvin int T = 1;
// cin >> T;
while (T--)
{
iamgoingto10of10();
}
}
/*
⣿⣿⣿⣿⣿⣿⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣠⣤⣤⠤⠤⠀⠒⠶⣀⠀⠀⠀⠈⣿⣿⣿⡿⠁
⣿⣿⣿⣿⣿⡗⠈⠀⠀⠀⣠⢀⣀⠀⣀⠀⢀⡀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠶⠚⣛⣉⠠⠀⣄⣀⠀⠀⠀⠀⠀⠀⠀⢿⣿⡿⠁⠀
⠃⠀⠀
⠀⣿⣼⡟⣿⣿⠀⢀⠢⠁⠀⣰⣜⣿⢿⣿⠿⢿⠟⢕⠢⠀⠃⠀⠀⠀⠀⠀⠀⠀⠐⠁⠈⠒⠒⠁⠀⠈⠅⠀⠀⠀⠀⠀⠀⡘⠟⢀⠀⠀
⠲⣿⢧⡃⣽⣿⠂⠀⠀⠀⠀⠉⠟⠉⠠⠈⠁⠀⠀⠀⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠺⠀⠀⠀⠀
⠀⡹⠸⣇⢸⣿⡅⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡄⠆⠀⠀⠀
⢠⡇⠀⣿⡘⢿⣧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀
⣼⣯⡈⠈⢯⠎⠻⡜⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡀⠀⠀
⣿⣷⣿⣆⢘⣆⠀⣷⢁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣷⠮⠁⠀⠀
⣿⣿⣿⣿⣶⣌⠦⣜⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡄⠀⣀⡄⠀⠀⠀⣰⣤⡠⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠐⢋⠄⠀⢀⢠
⣿⣿⣿⣿⣿⣿⣷⣎⣗⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢛⠙⠛⡈⠀⠜⠈⠈⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡂⢠⡴⣏⢧
⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣷⢿⡱⣏⠖
⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠠⢤⣤⣤⣤⣄⣀⣠⣀⣠⠶⠴⠦⠤⠒⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡿⣏⠷⠈⠌
⠀⠌⠙⠻⣿⣿⣿⣿⣿⣧⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢺⠟⠀⠀⠀⠀
⠀⠀⠀⠀⢉⠻⣿⣿⣿⣿⣧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⠀⡈⠇⠀⠀⠀⠀
⠀⠀⠀⠀⠈⠉⠙⠻⢿⣿⣿⣷⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠔⠇⢠⠃⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⢠⣿⣿⣿⣿⣿⣦⡀⢀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⠊⠁⠀⢠⠎⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⢠⣿⣿⣿⣿⣿⢹⣿⣞⡄⡀⠄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⠎⠀⠀⣀⠔⠁⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⣼⣿⣿⣿⣿⣿⣈⢻⣿⣧⣗⣤⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⢖⡡⠔⣠⡰⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⣼⣿⡏⠈⣿⡿⠁⠀⠀⠽⢿⣿⣾⣽⡷⣦⢤⡀⡄⣀⠀⡀⡀⠄⠔⣒⢱⣜⣮⡴⠚⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣾⣿⣿⡇⠀⢿⠁⠀⠀⠀⠀⠈⠙⣿⣿⣿⣿⣯⣷⡬⣫⡀⡱⣀⣖⣼⣾⣿⠟⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠻⡟⠙⡷⠀⠈⠀⠀⠀⠀⠀⠀⠀⠀⠙⠿⣿⣿⣿⣿⣷⣿⣿⣿⣿⠿⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⡇⠀⠀⠀⠀⠀⠀⠀⠀⠈⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⣻⣟⢿⣿⠟⣋⡀⠀⠀⠀⠀⢀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠹⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡾⢛⣽⣴⢴⣟⢙⣿⣦⡙⠑⠓⠙⠃⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
*/
Compilation message
joi2019_ho_t3.cpp: In function 'long long int calc(std::string, std::string)':
joi2019_ho_t3.cpp:48:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for (int i = 0; i + 1 < ans.size(); i += 2)
| ~~~~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |