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. day5_递归调用

    #递归的意思,函数自己调用自己#递归最多递归999次#递归的效率没有循环高 实例1-递归调用: count = 0 def say(): global count count += 1 print(' ...

  2. LeetCode 977 Squares of a Sorted Array 解题报告

    题目要求 Given an array of integers A sorted in non-decreasing order, return an array of the squares of ...

  3. IGMP协议

    IGMP报文格式: 4bit的IGMP版本(1)+4bit的IGMP类型(1-2)+8bit未用+16bit检验和(同ICMP)+32bit组地址(D类IP地址) 类型为1说明是由多播路由器发出的查询 ...

  4. mysql explain中的 “Select tables optimized away”

    mysql explain中的 “Select tables optimized away” http://blog.chinaunix.net/uid-10449864-id-2956845.htm ...

  5. 011-docker-安装-rabbitmq-management:3.7.13

    1.搜索镜像 docker search rabbitmq 2.拉取合适镜像 选择合适tag:https://hub.docker.com/,下载3.7.13 带web管理界面版本 docker pu ...

  6. jsp fmt标签格式化double数字

    <fmt:formatNumber value="${zjdl.ygdl }" pattern="0.00" />

  7. .net core中常用的属性

    //IsNullOrWhiteSpace()判断字符串是否为空 指示指定的字符串是 null.空还是仅由空白字符组成,如果字符串的空白String a="  ";IsNullOrE ...

  8. 快学Scala 2

    控制结构和函数 1.在Scala中,几乎所有构造出来的语法结构都有值.这个特性是为了使得程序更加精简,也更易读. (1)if表达式有值 (2)块也有值——是它最后一个表达式的值 (3)Scala的fo ...

  9. python基本运算符、比较运算符、赋值运算符、逻辑运算符

    # 基本运算符号: " + - * / % ** //" # a=20# b=30## print(a+b) #相加 当是: "+" a+b输出的结果:50## ...

  10. 设置 matlab 画图格式

    1:设置 matlab 画图格式 clear;clc; % load("array.mat"); % Bestallarray=array; % rllofcircle(Besta ...