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

Copy

9
RBGRRBRGG

output

Copy

2
RBGRGBRGR

input

Copy

8
BBBGBRRR

output

Copy

2
BRBGBRGR

input

Copy

13
BBRRRRGGGGGRR

output

Copy

6
BGRBRBGBGBGRG

思路:根据中间的改

代码;

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream> using namespace std; char a[200005];
int main()
{
int n;
cin>>n;
scanf("%s",a);
int s=0;
for(int t=0;t<n-1;t++)
{
if(a[t]==a[t+1])
{
s++;
if(a[t]!='R'&&a[t+2]!='R')
{
a[t+1]='R';
}
if(a[t]!='G'&&a[t+2]!='G')
{
a[t+1]='G';
}
if(a[t]!='B'&&a[t+2]!='B')
{
a[t+1]='B';
}
} } cout<<s<<endl;
puts(a); return 0;
}

Codeforces-D-Diverse Garland(思维)的更多相关文章

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

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

  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. Diverse Garland CodeForces - 1108D (贪心+暴力枚举)

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

  4. CodeForces 483C Diverse Permutation

    Diverse Permutation Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64 ...

  5. Educational Codeforces Round 60 C 思维 + 二分

    https://codeforces.com/contest/1117/problem/C 题意 在一个二维坐标轴上给你一个起点一个终点(x,y<=1e9),然后给你一串字符串代表每一秒的风向, ...

  6. Educational Codeforces Round 61 F 思维 + 区间dp

    https://codeforces.com/contest/1132/problem/F 思维 + 区间dp 题意 给一个长度为n的字符串(<=500),每次选择消去字符,连续相同的字符可以同 ...

  7. [Codeforces 1178D]Prime Graph (思维+数学)

    Codeforces 1178D (思维+数学) 题面 给出正整数n(不一定是质数),构造一个边数为质数的无向连通图(无自环重边),且图的每个节点的度数为质数 分析 我们先构造一个环,每个点的度数都是 ...

  8. Sorted Adjacent Differences(CodeForces - 1339B)【思维+贪心】

    B - Sorted Adjacent Differences(CodeForces - 1339B) 题目链接 算法 思维+贪心 时间复杂度O(nlogn) 1.这道题的题意主要就是让你对一个数组进 ...

  9. Codeforces 675C Money Transfers 思维题

    原题:http://codeforces.com/contest/675/problem/C 让我们用数组a保存每个银行的余额,因为所有余额的和加起来一定为0,所以我们能把整个数组a划分为几个区间,每 ...

  10. codeforces 483C.Diverse Permutation 解题报告

    题目链接:http://codeforces.com/problemset/problem/483/C 题目意思:给出 n 和 k,要求输出一个含有 n 个数的排列 p1, p2, ...,pn,使得 ...

随机推荐

  1. ios中的三种弹框《转》

    目前为止,已经知道3种IOS弹框: 1.系统弹框-底部弹框 UIActionSheet  (1)用法:处理用户非常危险的操作,比如注销系统等 (2)举例: UIActionSheet *sheet = ...

  2. C#高级参数params的使用

    params,可变参数,使用十分简单,看代码吧. using System; using System.Collections.Generic; using System.Linq; using Sy ...

  3. sizeof总结

    1.sizeof常用总结 ①与strlen比较       strlen 计算字符串的字符数,以"\0"为结束判断,但不统计结束符.   sizeof 计算数据(数组.变量.类型. ...

  4. java中字符串处理、串联和转换的几个常用方法,以及如果需要自己编程实现的具体实施步骤。

    What? 如何分类? 如何使用? //String 类提供处理 Unicode 代码点(即字符)(TT观点:指的莫非就是对象的意思.)和 Unicode 代码单元(即 char 值)的方法.(TT观 ...

  5. spring第三篇

    在昨天下午更新sprin第二篇中,叙述了将对象交给spring创建和管理,今天在spring第三篇中,主要写两个点一是spring的思想 二是spring中bean元素的属性配置. 1 spring思 ...

  6. 属性文件读写测试 PropertiesFileTest

    属性文件对于程序的拓展提供了很大的方便,但是什么该怎么去读写,怎么样读写才会最优呢?这里我做了一个简单的测试, 一般而言主要的有三种配置文件,*.ini,*.properties,*.xml,如果有兴 ...

  7. bit byte的关系

    字 word 字节 byte 位 bit 字长是指字的长度 1字=2字节(1 word = 2 byte) 1字节=8位(1 byte = 8bit)  一个字的字长为2个字节=2*8=16 一个字节 ...

  8. RGB565的转换

    RGB色彩模式也就是“红绿蓝”模式是一种颜色标准,是通过对红(R).绿(G).蓝(B)三种颜色通道的变化以及它们相互之间的叠加来得到各式各样的颜色的,RGB即是代表红.绿.蓝三个通道的颜色,这个标准几 ...

  9. yzm10的小简介

    yzm10,退役OIer,现役ACMer.大学生一枚,从高中开始接触编程(入门pascal...),过程基本自学,蒟蒻一只,在各大比赛划水打酱油..15年水得noip联二后退役,结束OI之旅.也是在1 ...

  10. Vue国际化的使用

    首先是是在main.js文件中把国际化引入进来 import Vue from 'vue' import App from './App' import router from './router' ...