You have a garland consisting of nn lamps. Each lamp is colored red, green or blue. The color of the ii-th lamp is sisi ('R', 'G' and '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 tt, then for each i,ji,j such that ti=tjti=tj should be satisfied |i−j| mod 3=0|i−j| mod 3=0. The value |x||x| means absolute value of xx, the operation x mod yx mod y means remainder of xx when divided by yy.

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 nn (1≤n≤2⋅1051≤n≤2⋅105) — the number of lamps.

The second line of the input contains the string ss consisting of nn characters 'R', 'G' and 'B' — colors of lamps in the garland.

Output

In the first line of the output print one integer rr — the minimum number of recolors needed to obtain a nice garland from the given one.

In the second line of the output print one string tt of length nn — a nice garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them.

Examples

input

Copy

3
BRB

output

Copy

1
GRB

input

Copy

7
RGBGRBB

output

Copy

3
RGBRGBR

思路:一共有6种情况,选出一个改变最小的

代码:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm> using namespace std; char a[200005];
char b[200005];
char c[200005];
int main() {
int n;
cin>>n;
scanf("%s",b);
int len=strlen(b);
strcpy(a,b); int maxn=999999; int s=0; for(int t=0; t<len; t+=3) {
if(a[t]!='R'&&t<len) {
a[t]='R';
s++;
}
if(a[t+1]!='G'&&t+1<len) {
a[t+1]='G';
s++;
}
if(a[t+2]!='B'&&t+2<len) {
a[t+2]='B';
s++;
}
} if(s<maxn) {
maxn=s;
strcpy(c,a); }
strcpy(a,b);
s=0;
for(int t=0; t<len; t+=3) {
if(a[t]!='R'&&t<len) {
a[t]='R';
s++;
}
if(a[t+1]!='B'&&t+1<len) {
a[t+1]='B';
s++;
}
if(a[t+2]!='G'&&t+2<len) {
a[t+2]='G';
s++; } } if(s<maxn) {
maxn=s;
strcpy(c,a); }
strcpy(a,b);
s=0; for(int t=0; t<len; t+=3) {
if(a[t]!='G'&&t<len) {
a[t]='G';
s++;
}
if(a[t+1]!='R'&&t+1<len) {
a[t+1]='R';
s++;
}
if(a[t+2]!='B'&&t+2<len) {
a[t+2]='B';
s++;
}
} if(s<maxn) {
maxn=s;
strcpy(c,a); }
strcpy(a,b);
s=0; for(int t=0; t<len; t+=3) {
if(a[t]!='G'&&t<len) {
a[t]='G';
s++;
}
if(a[t+1]!='B'&&t+1<len) {
a[t+1]='B';
s++;
}
if(a[t+2]!='R'&&t+2<len) {
a[t+2]='R';
s++;
}
} if(s<maxn) {
maxn=s;
strcpy(c,a); } strcpy(a,b);
s=0;
for(int t=0; t<len; t+=3) {
if(a[t]!='B'&&t<len) {
a[t]='B';
s++;
}
if(a[t+1]!='G'&&t+1<len) {
a[t+1]='G';
s++;
}
if(a[t+2]!='R'&&t+2<len) {
a[t+2]='R';
s++;
}
} if(s<maxn) {
maxn=s;
strcpy(c,a); }
strcpy(a,b);
s=0;
for(int t=0; t<len; t+=3) {
if(a[t]!='B'&&t<len) {
a[t]='B';
s++;
}
if(a[t+1]!='R'&&t+1<len) {
a[t+1]='R';
s++;
}
if(a[t+2]!='G'&&t+2<len) {
a[t+2]='G';
s++;
}
}
if(s<maxn) {
maxn=s;
strcpy(c,a); } cout<<maxn<<endl;
puts(c);
return 0;
}

Codeforces-C-Nice Garland(枚举+暴力)的更多相关文章

  1. Tomb Raider HihoCoder - 1829 (二进制枚举+暴力)(The 2018 ACM-ICPC Asia Beijing First Round Online Contest)

    Lara Croft, the fiercely independent daughter of a missing adventurer, must push herself beyond her ...

  2. HDU 3484 Matrix Game 枚举暴力

    上次周赛碰到这个题目,居然都没思路,真是不应该啊,起码也应该想到枚举法. 因为题目只允许每一row进行reverse操作,而每两列可以进行交换操作,所以首先把row的变化固定下来,即枚举第一列与第1- ...

  3. D. Diverse Garland Codeforces Round #535 (Div. 3) 暴力枚举+贪心

    D. Diverse Garland time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  4. Codeforces 626D Jerry's Protest(暴力枚举+概率)

    D. Jerry's Protest time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...

  5. codeforces 675B B. Restoring Painting(暴力枚举)

    题目链接: B. Restoring Painting time limit per test 1 second memory limit per test 256 megabytes input s ...

  6. CodeForces - 593A -2Char(思维+暴力枚举)

    Andrew often reads articles in his favorite magazine 2Char. The main feature of these articles is th ...

  7. Codeforces Gym 100015H Hidden Code 暴力

    Hidden Code 题目连接: http://codeforces.com/gym/100015/attachments Description It's time to put your hac ...

  8. Educational Codeforces Round 61 C 枚举 + 差分前缀和

    https://codeforces.com/contest/1132/problem/C 枚举 + 差分前缀和 题意 有一段[1,n]的线段,有q个区间,选择其中q-2个区间,使得覆盖线段上的点最多 ...

  9. codeforces 650D D. Image Preview (暴力+二分+dp)

    题目链接: http://codeforces.com/contest/651/problem/D D. Image Preview time limit per test 1 second memo ...

随机推荐

  1. hadoop-eclipse-plugin-2.6.0-cdh5.4.0 插件编译

    1.JDK配置 1) 安装jdk 2) 配置环境变量 JAVA_HOME.CLASSPATH.PATH等设置 2.Eclipse 1).下载eclipse-jee-juno-SR2.rar 2).解压 ...

  2. js-tree坑

    今天遇到一个js坑,一个页面,有两棵树,用同一个套参数初始化的,,,,当选择完另一个棵树之后,再操作另一颗树,不选择树节点,就会有错误出现,,,

  3. centos 端口iptables配置

    1.安装iptables yum install iptables* -y 2.打开端口 iptables -I INPUT -p tcp --dport -j ACCEPT 3.查看本机关于IPTA ...

  4. Bulma 源码解析之 .columns 类

    {说明} 这一部分的源码内容被我简化了,另外我还额外添加了一个辅助类 is-grow. .columns // 修饰类 &.is-centered justify-content: cente ...

  5. HDU 5038 Grade (水题,坑题)

    题意:给 n 个数,输出众数,但是如果所有的频率都相同但数不同输出 Bad Mushroom. 析:直接记录个数直接暴力就,就是要注意只有一种频率的时候. 代码如下: #pragma comment( ...

  6. Android之悬浮窗口实现(WindowManager)

    工作中遇到一些项目需要把窗体显示在最上层,像来电弹窗显示电话号码等信息.拦截短信信息显示给用户或者游戏中实现声音的调节,我们想这些数据放在最上层,activity就满足不了我们的需求了,有些开发者使用 ...

  7. python 中的异常处理与种类

    异常处理是Python工程中补课避免的,进行异常处理,可以帮我们调试代码,使代码找起问题更加简单,更加容易哦. 一般都是利用Try,比较简单,代码也不复杂. try: print 'try...' r ...

  8. static的功能

    static : 翻译成中文是静态的意思.  使用内部函数的好处是:不同的人编写不同的函数时,不用担心自己定义的函数,是否会与其它文件中的函数同名,因为同名也没有关系.   在C语言中,static的 ...

  9. vue配置vue-router

    首先理清一下几个路由的基础概念: 1)route是一条路由,也就是映射,即A按钮→A内容,以数组形式存储 2)toutes:[]是一组路由,里面包含了若干条route,即route[{A按钮→A内容} ...

  10. officeaddin开发->excel,word另存为html,xml,csv,txt设置编码格式

    在excel中设置保存之后的编码格式,需要获取到Microsoft.Office.Interop.Excel.Workbook然后设置其中的webOpetions的编码格式就可以了. workbook ...