Chips Moving(缺口移动)

http://codeforces.com/problemset/problem/1213/A

You are given nn chips on a number line. The ii-th chip is placed at the integer coordinate xixi. Some chips can have equal coordinates.

You can perform each of the two following types of moves any (possibly, zero) number of times on any chip:

  • Move the chip ii by 22 to the left or 22 to the right for free (i.e. replace the current coordinate xixi with xi−2xi−2 or with xi+2xi+2);
  • move the chip ii by 11 to the left or 11 to the right and pay one coin for this move (i.e. replace the current coordinate xixi with xi−1xi−1or with xi+1xi+1).

Note that it's allowed to move chips to any integer coordinate, including negative and zero.

Your task is to find the minimum total number of coins required to move all nn chips to the same coordinate (i.e. all xixi should be equal after some sequence of moves).

Input

The first line of the input contains one integer nn(1≤n≤1001≤n≤100) — the number of chips.

The second line of the input contains nn integers x1,x2,…,xnx1,x2,…,xn (1≤xi≤1091≤xi≤109), where xixi is the coordinate of the ii-th chip.

Output

Print one integer — the minimum total number of coins required to move all nn chips to the same coordinate.

Examples

Input

3
1 2 3

Output

1

Input

5
2 2 2 3 3

Output

2

Note

In the first example you need to move the first chip by 22 to the right and the second chip by 11to the right or move the third chip by 22 to the left and the second chip by 11 to the left so the answer is 11.

In the second example you need to move two chips with coordinate 33 by 11 to the left so the answer is 22.

 看了无数遍不知道干啥的题~~~哎,比赛完了才知道~~~崩溃(=@__@=)

题意:

给你一些坐标,要求把所有坐标都变成一样的。条件是每次移动两个位置免费,每次移动一个位置需要花费1硬币,问最少花费的硬币数是多少?(就是求奇数或偶数最小的那个),因为奇数坐标要想移动到偶数坐标上需要花费1硬币(无论怎样都需要花费一硬币),因为2个2个移动都是免费的,最后总是要剩下一个。偶数坐标移动到奇数坐标上也是如此。

方法:

可以先统计奇数个数,最后比较奇数个和偶数个大小即可。

代码:

 

#include<stdio.h>
#include<string.h>
#include<algorithm>
typedef long long ll;
using namespace std;
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        int odd=0,even=0,a;
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a);
            if(a&1)
            odd++;
            else even++;
        }
        printf("%d\n",odd>even?even:odd);
    }
    return 0;
}

好好学习~~

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

嵩韵儿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值