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. Spring装配各种类型bean

    一.单属性值的装配 //setter注入,提供无参构造器,提供setXX方法 <property name="" value=""></pro ...

  2. Solr查询错误

    报错: Exception in thread "main" java.lang.VerifyError: Bad return type Exception Details: L ...

  3. Linux reboot后数据库无法自动启动

    需将以下由N改为Y orcl:/data/oracle_db/product/13.2.0/db_1:Y Last login: Thu Aug 27 16:36:19 2015 from 10.10 ...

  4. 【总结整理】openlayer加载搜狗地图,qq地图,mapabc

    qq    http://www.cnblogs.com/gisvip/archive/2012/11/01/2750493.html mapabc    http://www.cnblogs.com ...

  5. gym - 101673I Twenty Four, Again (表达式树枚举)

    题意及思路 模拟场上用一般方法枚举非常麻烦,一个小时没写出来,还是自己太菜了...用表达式树枚举有一个好处,判断需不需要加括号非常方便,只有当前节点运算符的优先级高于子节点的时候,才需要给子节点加一个 ...

  6. Hibernate和JPA

    ORM(Object/Relational Mapping : 对象关系映射)就是利用描述对象和数据库之间映射的元数据,自动(且透明)的将java应用程序中的对象持久化到关系数据库的表中.HIbern ...

  7. JavaPersistenceWithHibernate第二版笔记-第七章-004Mapping a map(@MapKeyEnumerated 、 @MapKeyTemporal、@MapKeyColumn)

    一.结构 二.代码 1. package org.jpwh.model.collections.mapofstrings; import org.jpwh.model.Constants; impor ...

  8. JavaPersistenceWithHibernate第二版笔记-第六章-Mapping inheritance-008Polymorphic many-to-one associations(@ManyToOne、@Inheritance、)

    一.结构 二.代码 1. package org.jpwh.model.inheritance.associations.manytoone; import org.jpwh.model.Consta ...

  9. java全栈day04--方法

    day04内容介绍 1  方法基础知识 2  方法高级内容 3  方法案例 一  方法的概念 A:为什么要有方法 提高代码的复用性 B   什么是方法 完成特定功能的代码块 修饰符  返回值类型  方 ...

  10. CefSharp使用一

    一.使用NuGet搜索CefSharp然后下载CefSharp.WinForms和CefSharp.Common 二.引用CefSharp.Windows,CefSharp,CefSharp三个dll ...