Prefixes

Nikolay got a string s of even length n, which consists only of lowercase Latin letters ‘a’ and ‘b’. Its positions are numbered from 1 to n.

He wants to modify his string so that every its prefix of even length has an equal amount of letters ‘a’ and ‘b’. To achieve that, Nikolay can perform the following operation arbitrary number of times (possibly, zero): choose some position in his string and replace the letter on this position with the other letter (i.e. replace ‘a’ with ‘b’ or replace ‘b’ with ‘a’). Nikolay can use no letters except ‘a’ and ‘b’.

The prefix of string s of length l (1≤l≤n) is a string s[1…l].

For example, for the string s=“abba” there are two prefixes of the even length. The first is s[1…2]=“ab” and the second s[1…4]=“abba”. Both of them have the same number of ‘a’ and ‘b’.

Your task is to calculate the minimum number of operations Nikolay has to perform with the string s to modify it so that every its prefix of even length has an equal amount of letters ‘a’ and ‘b’.

Input
The first line of the input contains one even integer n (2≤n≤2⋅105) — the length of string s.

The second line of the input contains the string s of length n, which consists only of lowercase Latin letters ‘a’ and ‘b’.

Output
In the first line print the minimum number of operations Nikolay has to perform with the string s to modify it so that every its prefix of even length has an equal amount of letters ‘a’ and ‘b’.

In the second line print the string Nikolay obtains after applying all the operations. If there are multiple answers, you can print any of them.

Examples

Input
4
bbbb
Output
2
abba

Input
6
ababab

Output
0
ababab

Input
2
aa

Output
1
ba

Note
In the first example Nikolay has to perform two operations. For example, he can replace the first ‘b’ with ‘a’ and the last ‘b’ with ‘a’.

In the second example Nikolay doesn’t need to do anything because each prefix of an even length of the initial string already contains an equal amount of letters ‘a’ and ‘b’.

已经要求n为偶数,每个偶数个都要包含相同的a和b,可以推断出,每两个都要是a和b才符合。所以两个连在一起的字符相同(首下标为0时,两数偶在前奇在后),就要进行更换。

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	char s[200010];
	cin>>n>>s;
	int t=0;
	for(int i=0;i<n;++i){
	    if(s[i]=='a'&&s[i+1]=='a'){
	    	s[i]='b';
	    	t++;
		}
		else if(s[i]=='b'&&s[i+1]=='b'){
			s[i]='a';
			t++;
		}
		i+=1;
	}
	cout<<t<<endl<<s<<endl;
	return 0;
 } 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值