CodeforcesJun 07, 2025

Chips Moving

Hazrat Ali

Codeforces

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 2 to the left or 2 to the right for free (i.e. replace the current coordinate xixi with xi2xi−2 or with xi+2xi+2);
  • move the chip ii by 1 to the left or 1 to the right and pay one coin for this move (i.e. replace the current coordinate xixi with xi1xi−1 or 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 (1n1001≤n≤100) — the number of chips.

The second line of the input contains nn integers x1,x2,,xnx1,x2,…,xn (1xi1091≤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

Solution

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    int even = 0, odd = 0;
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        if (x % 2 == 0)
        {
            even++;
        }
        else
        {
            odd++;
        }
    }
    cout << min(even, odd) << endl;
    return 0;
}



Comments