time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You have a garland consisting of B' — colors of lamps in the garland).

You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is nice.

A garland is called nice if any two lamps of the same color have distance divisible by three between them. I.e. if the obtained garland is y.

For example, the following garlands are nice: "RGBRGBRG", "GB", "R", "GRBGRBG", "BRGBRGB". The following garlands are not nice: "RR", "RGBG".

Among all ways to recolor the initial garland to make it nice you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them.

Input

The first line of the input contains one integer 1≤n≤2⋅105) — the number of lamps.

The second line of the input contains the string B' — colors of lamps in the garland.

Output

In the first line of the output print one integer nice garland from the given one.

In the second line of the output print one string any of them.

Examples
input
Copy
3
BRB
output
Copy
1
GRB
input
Copy
7
RGBGRBB
output
Copy
3
RGBRGBR


next_permutation(a, a + 3)
输出数组a的字典序的全排列。

eg
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
  int ans[4]={1,2,3,4};
  sort(ans,ans+4);    /* 这个sort可以不用,因为{1,2,3,4}已经排好序*/
  do                             /*注意这步,如果是while循环,则需要提前输出*/
  {
    for(int i=0;i<4;++i)
      cout<<ans[i]<<" ";
    cout<<endl;
  }while(next_permutation(ans,ans+4));
return 0;
}

 

#include<iostream>
#include<algorithm>
#include<string.h>
#include<map>
#include<stdio.h>
#include<math.h>
using namespace std;
#define ll long long
using namespace std;
const int maxn = 2e5 + 10;
char str[maxn], s1[maxn], s2[maxn];
int n, a[4];

int main()
{
  cin >> n >> str;
  map<int, char> m;
  m[0] = 'R'; 
  m[1] = 'G'; 
  m[2] = 'B';
  int ans = maxn * 2;
  a[1] = 1, a[2] = 2;
  do 
  {
    s1[0] = m[a[0]];
    s1[1] = m[a[1]];
    s1[2] = m[a[2]];
    for (int q = 3; q < n; q++)
    {
      s1[q] = s1[q - 3];
    }
    int cnt = 0;
    for (int q = 0; q < n; q++)
    {
      if (s1[q] != str[q])
        cnt++;
    }
    if (cnt < ans)
    {
      ans = cnt;
      strcpy(s2, s1);
    }
  } while (next_permutation(a, a + 3));
  printf("%d\n", ans);
  for (int i = 0; i < n; i++)
    printf("%c", s2[i]);
  return 0;
}

 

相关文章: