Anatoly and Cockroaches

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 to alternate. 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.

Example

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

 

要求标准是红黑交叉,无非是红开头,或者黑开头,按照这两个标准比对,各需要多少次取小,如何比对呢,记录红色不对的个数,和黑色不对的个数,一红一黑交换,多出来的改颜色,所以就是找出红和黑的最大值,这样问题就简单了。

 

代码:

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    int a,b,c,d;
    a = b = c = d = 0;
    for(int i = 0;i < n;i ++)
    {
        if(s[i] == 'r' && i%2)a ++;
        else if(s[i] == 'b' && i%2 == 0)b ++;
        if(s[i] == 'r' && i%2 == 0)c ++;
        else if(s[i] == 'b' && i%2)d ++;
    }
    cout<<(max(a,b)>max(c,d)?max(c,d):max(a,b));
}

 

转载于:https://www.cnblogs.com/8023spz/p/7668567.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值