All problems

Problem 667

Minimum Cost to Move Chips to The Same Position

Easy · 10 pts · Array, Math, Greedy

Problem

There are N chips, and chip i is at position P[i] (several chips may share a position). Moving a chip by 2 positions in either direction is free, while moving it by 1 position costs 1. Find the minimum total cost to move all chips to the same position. Free moves let any chip reach every position of the same parity, so only the parity matters: move the smaller group (odd or even positions) by one step each.

Input

The first line contains an integer N, the size of the array. The second line contains N space-separated integers A[0], A[1], ..., A[N-1].

Output

Print the minimum cost.

Constraints

1 <= N <= 100; 1 <= P[i] <= 10^9

Example input

5
2 2 2 3 3

Example output

2

Explanation

Chips at 2 2 2 3 3: the two chips at position 3 can each move one step to 2 for a cost of 1 each. Moving the three chips at 2 would cost 3, so the answer is 2.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Maximum Ice Cream Bars Next: Split a String in Balanced Strings