This page is still under construction.

Parts of this page are still being built. What you see may change.

Flipping Coins

Interview

Time limit1sMemory limit128 MB

Summary
Count the heads and tails and flip the coins on the less frequent side so all coins show the same face.
Level

Easy1 of 10

Topics
Greedy, Array
Solved
No attempts yet

Problem

Bajtek has nn coins. Each coin has two sides, heads and tails, and all of them are currently lying on a table. Bajtek wants every coin to show heads, or every coin to show tails. Find the minimum number of coins he has to flip to the other side to achieve this.

Input

The first line contains one integer nn (1≤n≤1061 \le n \le 10^6), the number of coins.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n separated by spaces. Here aia_i describes the ii-th coin: it is 00 if the coin shows heads and 11 if it shows tails.

Output

Print a single integer: the minimum number of coins Bajtek has to flip so that all coins show the same side.

Examples1

  1. Example 1

    Input
    6
    1 0 1 1 1 0
    
    Expected output
    2