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
3
BRB
Output
1
GRB
Input
7
RGBGRBB
Output
3
RGBRGBR 题意:简单词汇,可以自行阅读。
思路:因为题目的限制,导致如果这个字符串的长度大于等于3的时候,一定是RBG这三个字符的某一个排列的循环。
那么RBG一共最多有6种排列方式,( A(3,3) )
我们手写出这6种全排列。
{
"RGB",
"RBG",
"GRB",
"BRG",
"GBR",
"BGR"};
然后以此每一种排列去和字符串进行匹配,找出让字符串为3字符循环的最小消耗即可,
中间开一个变量k来记录是哪个排列方式让消耗最小,然后最后输出他的循环节即可。
细节看代码。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=;while(b){if(b%)ans=ans*a%MOD;a=a*a%MOD;b/=;}return ans;}
inline void getInt(int* p);
const int maxn=;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int n;
char a[maxn];
char s[][]=
{
"RGB",
"RBG",
"GRB",
"BRG",
"GBR",
"BGR"};
int main()
{
gg(n);
scanf("%s",a);
if(n==)
{
printf("0\n");
printf("%s",a);
}else
{
int ans=inf;
int cnt;
int k;
repd(i,,)
{
cnt=;
repd(j,,n-)
{
if(a[j]!=s[i][(j%)])
{
cnt++;
}
}
if(cnt<ans)
{
ans=cnt;
k=i;
}
}
printf("%d\n",ans );
repd(i,,n-)
{
putchar(s[k][(i%)]);
}
printf("\n");
} return ;
} inline void getInt(int* p) {
char ch;
do {
ch = getchar();
} while (ch == ' ' || ch == '\n');
if (ch == '-') {
*p = -(getchar() - '');
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * - ch + '';
}
}
else {
*p = ch - '';
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * + ch - '';
}
}
}


Nice Garland CodeForces - 1108C (思维+暴力)的更多相关文章

  1. C. Nice Garland Codeforces Round #535 (Div. 3) 思维题

    C. Nice Garland time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  2. 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 ...

  3. codeforces 768 C. Jon Snow and his Favourite Number(思维+暴力)

    题目链接:http://codeforces.com/contest/768/problem/C 题意:给出n个数,k个操作,和一个x,每次操作先排序然后对奇数位数进行xor x操作,最后问k次操作后 ...

  4. Diverse Garland CodeForces - 1108D (贪心+暴力枚举)

    You have a garland consisting of nn lamps. Each lamp is colored red, green or blue. The color of the ...

  5. CodeForces - 1244D (思维+暴力)

    题意 https://vjudge.net/problem/CodeForces-1244D 有一棵树,有3种颜色,第i个节点染成第j种颜色的代价是c(i,j),现在要你求出一种染色方案,使得总代价最 ...

  6. CodeForces - 1248D1 (思维+暴力)

    题意 有一个括号序列,你可以选择两个位置i,j(i可以等于j),进行交换.使得最后的循环位置(i的数目)最大. 循环位置:i(0<=i<len),将前i个字符移到最后,得到的新序列是合法的 ...

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

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

  8. CodeForces - 1230C(思维/暴力)

    题意 https://vjudge.net/problem/CodeForces-1230C 给了你总共有21张多米诺骨牌,每张牌有两个面,然后给你一个无向图,保证没有环和一个顶点多条边的情况存在.现 ...

  9. CodeForces - 1228D (暴力+思维+乱搞)

    题意 https://vjudge.net/problem/CodeForces-1228D 有一个n个顶点m条边的无向图,在一对顶点中最多有一条边. 设v1,v2是两个不相交的非空子集,当满足以下条 ...

随机推荐

  1. Python对文件的解压和压缩

    zipfile: 解压: import os, zipfile serverzip_path = 'D:\\server.zip' serverzip_target_path = 'd:\\2' f ...

  2. [HBase_1] HBase安装与配置

    0. 说明 1. 简介 1.1 简介 基于 HDFS 的大表软件(实时数据库) 十亿行 x 百万列 x 上千个版本 版本是通过 mvcc 技术控制:multiple version concurren ...

  3. 我的第一个SolidWorks图

    1. 学习到的知识点 2. 完成的工程图 3. 感受 学习是一种快乐,学到新的知识要学会分享,只要坚持,就有那么一点点的成就. 4. 参考 SolidWorks帮助文档

  4. Windows下mysql服务的安装与卸载

    安装 mysqld -install 也可以指定mysql安装服务的文件 my.ini文件配置好后就可以在cmd中安装mysqld服务了,在cmd中运行命令:mysqld --install MySQ ...

  5. Windows Live Writer 2012在Blogjava管理和发布博客

    下载Windows Live Writer 2012的完整版本(wlsetup-all.exe),安装的时候减少网络下载消耗的时间.注:有些平台可能还需要下载DotNet3.5(dotnetfx35. ...

  6. 【C编程基础】多线程编程

    基础知识 1.基本概念 (1)线程,即轻量级进程(LWP:LightWeight Process),是程序执行流的最小单元. 线程是进程中的一个实体,是被系统独立调度和分派的基本单位. (2)线程同步 ...

  7. python获取数据网页数据并创建文件夹保存(基于python3.6)

    from urllib.parse import urljoin import urllib.request from bs4 import BeautifulSoup import os impor ...

  8. JavaScript模块载入框架sea.js 学习一

    简单总结sea.js 学习 文件文件夹结构   /sea/sea.js      下载地址  http://seajs.org/docs/#downloads   /sea/jquery-sea.js ...

  9. UVA140-Bandwidth(搜索剪枝)

    Problem UVA140-Bandwidth Time Limit: 3000 mSec  Problem Description Given a graph (V, E) where V is ...

  10. [国家集训队]happiness

    嘟嘟嘟 就这么建. --- #include<cstdio> #include<iostream> #include<cmath> #include<algo ...