codeforce719B

B. Anatoly and Cockroaches
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are n cockroaches living in Anatoly's room.

Anatoly just made all his cockroaches to form a single line. As he is a perfectionist, he would like the colors of cockroaches in the line toalternate. He has a can of black paint and a can of red paint. In one turn he can either swap any two cockroaches, or take any single cockroach and change it's color.

Help Anatoly find out the minimum number of turns he needs to make the colors of cockroaches in the line alternate.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of cockroaches.

The second line contains a string of length n, consisting of characters 'b' and 'r' that denote black cockroach and red cockroach respectively.

Output

Print one integer — the minimum number of moves Anatoly has to perform in order to make the colors of cockroaches in the line to alternate.

Examples
input
5
rbbrr
output
1
input
5
bbbbb
output
2
input
3
rbr
output
0
Note

In the first sample, Anatoly has to swap third and fourth cockroaches. He needs 1 turn to do this.

In the second sample, the optimum answer is to paint the second and the fourth cockroaches red. This requires 2 turns.

In the third sample, the colors of cockroaches in the line are alternating already, thus the answer is 0.


其实这个题想通了也挺水的,就是一开始遍历找需要改的字符的时候想错了,刚开始我是遍历找判断i和i+1是否相同,结果后来发现有好多种情况不能解决,以为后半部分的计算方法有错,就卡住了,其实仔细思考后发现找需要修改的字符的时候可以和正确排列的字符串比较,正确字符串有两种情况,b开头或者r开头,都记录后取最小值就行了
#include
#include
#include
#define M 100008
using namespace std;
char s[M];
char c[M];
int main()
{
	int n;
	scanf("%d",&n);
	scanf("%s",s);
	int bb=0,rr=0;
	int j=0;
	for(int i=0;i


你可能感兴趣的:(codeforces)