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 题意:输入一个字符串,按照GRB或者这三个字符组成的其他的顺序依次出现。计算哪些字符违反规则,并纠正。要使纠正次数最少,输出纠正次数和纠正过的字符串。
思路:使用next_permutation()函数,把GRB按照字典序组合一遍,然后再判断输入字符串与这6个组合的不同次数。找到最小的次数,保存这个组合。然后输出
下面是ac代码
#include<bits/stdc++.h>
using namespace std; char p[3] = {'R','G','B'};
int ans = 1e9; int main(){
string s,res;
int n;
cin>>n;
cin>>s;
sort(p,p+3); do{
int count = 0;
for(int i = 0; i < n; i++)
if(s[i] != p[i%3]) // p 会溢出,所以 mod 3 。
count++; if(count < ans)
ans = count, res = p; }while(next_permutation(p,p+3)); cout<<ans<<endl;
for(int i = 0; i < n; i++)
{
cout<<res[i%3];
}
return 0;
}

1.23 codeforces div3 C.Nice Garland的更多相关文章

  1. Codeforces Round #535 (Div. 3) [codeforces div3 难度测评]

    hhhh感觉我真的太久没有接触过OI了 大约是前天听到JK他们约着一起刷codeforces,假期里觉得有些颓废的我忽然也心血来潮来看看题目 今天看codeforces才知道居然有div3了,感觉应该 ...

  2. 【codeforces 758B】Blown Garland

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  3. Codeforces Div3 #501 A-E(2) F以后补

    感觉自己有点强迫症  不都写出来就找理由不写题解 http://codeforces.com/contest/1015   题目链接 A. Points in Segments 题目意思  n个线段  ...

  4. Codeforces 758B:Blown Garland(模拟)

    http://codeforces.com/problemset/problem/758/B 题意:给出一个字符串,每4个位置对应一个颜色,如果为‘!’的话,代表该灯泡是坏的,问最后每个颜色坏的灯泡的 ...

  5. CF codeforces A. New Year Garland【Educational Codeforces Round 79 (Rated for Div. 2)】

    A. New Year Garland time limit per test 1 second memory limit per test 256 megabytes input standard ...

  6. Codeforces Div3 #498 A-F

                                                                               . A. Adjacent Replacement ...

  7. 【codeforces div3】【E. Cyclic Components】

    E. Cyclic Components time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  8. 2018.09.23 codeforces 1053B. Vasya and Good Sequences(前缀和)

    传送门 考试的时候卡了一会儿. 显然这个答案只跟二进制位为1的数量有关. 还有一个显然的结论. 对于一个区间[l,r][l,r][l,r],如果其中单个数二进制位为1的数量最大值不到区间所有数二进制位 ...

  9. 2018.09.23 codeforces 1053A. In Search of an Easy Problem(gcd)

    传送门 今天的签到题. 有一个很显然的结论,gcd(n∗m,k)≤2gcd(n*m,k)\le 2gcd(n∗m,k)≤2. 本蒟蒻是用的行列式求三角形面积证明的. 如果满足这个条件,就可以直接构造出 ...

随机推荐

  1. [X][xrandr][archlinux] 手动调整显示器分辨率

    有一些时候,电脑并不能正确的识别出显示器的最大分辨率,这有可能是软件的原因,硬件的原因,显示器的原因,VGA线的原因等其他原因. 我遇到的情况,是开机时候连着VGA的话,就可以正确识别.如果使用中间进 ...

  2. delphi 把数据库图片的存取

    procedure TForm1.Button1Click(Sender: TObject); // 插入图片过程 var Stream:TMemoryStream;begin try Stream ...

  3. 基于VUE,VUX组件开发的网易新闻页面搭建过程

    根据妙味课堂上的一个教程练习总结,供自己复习用 一.功能介绍 一个网易新闻客户端的浏览页面,通过网易新闻的api接口实时获取新闻数据,用vux搭建样式框架,以轮播图,文字滚动,图文列表等形式把内容展示 ...

  4. El表达式对照表

    设置  session.getAttribute("date" "date") 取得username的值   (String)session.getValue( ...

  5. 【python基础】常用的内置函数

    python基础之内置函数 参考: http://www.runoob.com/python/python-built-in-functions.html -zip() zip函数接受任意多个(包括0 ...

  6. CSS中position属性介绍(新增sticky)

    position的含义是指定类型,取值类型可以有:static.relative.absolute.fixed.inherit 和 sticky,这里sticky是CSS3新发布的一个属性. 1.po ...

  7. Vue main.js 文件中全局组件注册部分

    在 \src\components\index.js 文件中export组件 import HeaderList from './HeaderList' import HeaderMenu from ...

  8. VS Code 管理 .NET Core解决方案

    本练习要使用Visual studio code完成一个包含多个项目的解决方案,包括类库和Web项目.结合Visual Studio Code和.NET Core CLI,创建项目结构如下: pied ...

  9. 数据库文件MDF的空间占满了,没有自动增长是怎么回事?

    前提: (1)磁盘C盘.数据文件所在盘均有空间 (2)没有对数据文件设置maxSize   (3)做过数据库服务器重启,仍没有效果 (4)但是同一个实例上的其他数据库没问题 (5)配额也查了,没问题 ...

  10. vim常用指令整理小结

    启动Vim后,默认是在 Normal 模式下,但是我们有时不知道是在编辑模式还是normal模式,按ESC键就可以返回normal模式.因为所有的命令都需要在Normal模式下使用,所以建议多按几下E ...