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

A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is 11) have distinct colors.

In other words, if the obtained garland is tt then for each ii from 11 to n−1n−1 the condition ti≠ti+1ti≠ti+1 should be satisfied.

Among all ways to recolor the initial garland to make it diverse 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 diverse garland from the given one.

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

Examples

Input
9
RBGRRBRGG
Output
2
RBGRGBRGR
Input
8
BBBGBRRR
Output
2
BRBGBRGR
Input
13
BBRRRRGGGGGRR
Output
6
BGRBRBGBGBGRG 题意:给定一个字符串,只包含RGB三个字符,你可以改变某些字符使之这个字符串相邻的字符不相等。
那么我们只需要枚举从第二个字符开始的每一个字符串,判定是否和前面的字符相等,如果相等就改成不和后面字串相等字符,这样消耗就一定最小。
很水的一题,细节看code。
#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 s[maxn];
int main()
{
gg(n);
scanf("%s",s);
int ans=;
repd(i,,n-)
{
if(s[i]==s[i-])
{
if(s[i]=='B')
{
if(s[i+]!='R')
{
s[i]='R';
}else
{
s[i]='G';
}
}else if(s[i]=='R')
{
if(s[i+]!='B')
{
s[i]='B';
}else
{
s[i]='G';
}
}else if(s[i]=='G')
{ if(s[i+]!='R')
{
s[i]='R';
}else
{
s[i]='B';
}
}
ans++;
} }
printf("%d\n",ans );
printf("%s\n", s);
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 - '';
}
}
}

Diverse Garland CodeForces - 1108D (贪心+暴力枚举)的更多相关文章

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

  2. Array and Segments (Easy version) CodeForces - 1108E1 (暴力枚举)

    The only difference between easy and hard versions is a number of elements in the array. You are giv ...

  3. codeforces 466c(暴力枚举)

    题目链接 思路如下 *题意: 给定一个序列,问有多少种方案可以将此序列分割成3个序列元素和完全相同的子序列.(子序列不能为空).即问有多少个点对(i,j)满足a[1]+-+a[i-1]=a[i]+a[ ...

  4. Codeforces 1108D - Diverse Garland - [简单DP]

    题目链接:http://codeforces.com/problemset/problem/1108/D time limit per test 1 secondmemory limit per te ...

  5. Codeforces Round #349 (Div. 1) B. World Tour 最短路+暴力枚举

    题目链接: http://www.codeforces.com/contest/666/problem/B 题意: 给你n个城市,m条单向边,求通过最短路径访问四个不同的点能获得的最大距离,答案输出一 ...

  6. Codeforces Round #298 (Div. 2) B. Covered Path 物理题/暴力枚举

    B. Covered Path Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/534/probl ...

  7. Codeforces 425A Sereja and Swaps(暴力枚举)

    题目链接:A. Sereja and Swaps 题意:给定一个序列,能够交换k次,问交换完后的子序列最大值的最大值是多少 思路:暴力枚举每一个区间,然后每一个区间[l,r]之内的值先存在优先队列内, ...

  8. CodeForces 742B Arpa’s obvious problem and Mehrdad’s terrible solution (暴力枚举)

    题意:求定 n 个数,求有多少对数满足,ai^bi = x. 析:暴力枚举就行,n的复杂度. 代码如下: #pragma comment(linker, "/STACK:1024000000 ...

  9. Codeforces Round #266 (Div. 2)B(暴力枚举)

    很简单的暴力枚举,却卡了我那么长时间,可见我的基本功不够扎实. 两个数相乘等于一个数6*n,那么我枚举其中一个乘数就行了,而且枚举到sqrt(6*n)就行了,这个是暴力法解题中很常用的性质. 这道题找 ...

随机推荐

  1. SqlServer执行Insert命令同时判断目标表中是否存在目标数据

    针对于已查询出数据结果, 且在程序中执行Sql命令, 而非数据库中的存储过程 INSERT INTO TableName (Column1, Column2, Column3, Column4, Co ...

  2. PHP中的Session工作原理

    一直在使用session存储数据,一直没有好好总结一下session的使用方式以及其工作原理,今天在这里做一下梳理. 这里的介绍主要是基于php语言,其他的语言操作可能会有差别,但基本的原理不变. 1 ...

  3. windows入侵

    一, ping 用来检查网 络是否通畅或者网络连接速度的命令.作为一个生 活在网络上的管理员或者黑 客来说, ping 命令是第一个必须掌握的 DOS 命令,所利用的原理是这样的网络上的机器都有唯一确 ...

  4. 第六章 第一个Linux驱动程序: 统计单词个数

    一.编写Linux驱动程序的步骤 第1 步:建立Linux 驱动骨架(装载和卸载Linux 驱动) 骨架部分主要是Linux驱动的初始化和退出函数,代码如下: #include <linux/m ...

  5. Java反射机制小结和实际操作

    一.什么是反射 1.编译和运行 在了解什么是Java反射机制前,先聊聊Java的编译和运行. 还记得第一次使用记事本编写第一个Java程序的场景吗?通过命令窗口,使用javac命令编译一个.java文 ...

  6. February 22nd, 2018 Week 8th Thursday

    Confine yourself to the present. 着眼当下. The morning wind spreads its fresh smell, we should get up an ...

  7. 【HNOI2016】最小公倍数

    [HNOI2016]最小公倍数 容易想到先将所有边按\(a\)排序,然后处理\(b\).(然后我就不会了 我们按\(a\)的权值分块,处理\(a\)权值位于第\(k\)个块的询问的时候,我们先将询问按 ...

  8. linux学习笔记整理(五)

    第六章 Centos7用户管理本节所讲内容:6.1 用户和组的相关配置文件6.2 管理用户和组6.3实战:进入centos7 紧急模式恢复root密码 用户一般来说是指使用计算机的人,计算机对针使用其 ...

  9. 【angularJS】过滤器

    1.分类: <1>内置过滤器(见4) <2>自定义过滤器 2.作用:接收一个输入,通过某个规则进行处理,然后返回处理后的结果 3.应用: <1>在模板中使用 用法 ...

  10. 0、原生jdbc工厂类

    一.代码结构 二.JDBCFactory.java package com.test; import java.io.IOException; import java.io.InputStream; ...