题库练习 Little Elephant and Cards
← 上一题 下一题 →

A8616 | Little Elephant and Cards

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

The Little Elephant loves to play with color cards.

He has $n$ cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elephant can turn any card to the other side. The Little Elephant thinks that a set of cards on the table is funny if at least half of the cards have the same color (for each card the color of the upper side is considered).

Help the Little Elephant to find the minimum number of moves needed to make the set of $n$ cards funny.

输入格式

The first line contains a single integer $n$ $(1<=n<=10^{5})$ — the number of the cards. The following $n$ lines contain the description of all cards, one card per line. The cards are described by a pair of positive integers not exceeding $10^{9}$ — colors of both sides. The first number in a line is the color of the front of the card, the second one — of the back. The color of the front of the card may coincide with the color of the back of the card.

The numbers in the lines are separated by single spaces.

输出格式

On a single line print a single integer — the sought minimum number of moves. If it is impossible to make the set funny, print -1.

输入输出样例

输入 #1
3
4 7
4 7
7 4
输出 #1
0
输入 #2
5
4 7
7 4
2 11
9 7
1 1
输出 #2
2
C++ 编辑器
输入
输出