

Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 点
問題文
枚のカードが一列に伏せられており、各カードには整数 または が書かれています。
番目のカードに書かれている整数を とします。
あなたの目的は を当てることです。
次のことが分かっています。
- について は偶数である。
あなたは魔法使いです。次の魔法を何度でも使うことができます。
魔法: コストを 払う。カードを 枚選び、そのカードに書かれた整数 を知る。
最小で何コスト払えば、 全てを確実に当てることができるでしょうか。
なお、与えられる入力には矛盾がないことが保証されます。
制約
- 入力は全て整数である。
- の組は互いに異なる。
- 与えられる入力には矛盾がない(すなわち、条件を満たす が存在する)。
入力
入力は以下の形式で標準入力から与えられる。
出力
全てを確実に当てるために払う必要のあるコストの合計の最小値を出力せよ。
入力例 1Copy
3 1 1 2 1
出力例 1Copy
2
枚目と 枚目のカードに対してそれぞれ 回ずつ魔法を使えば、 全てを当てることができます。
入力例 2Copy
6 5 1 2 1 2 3 2 1 3 3 4 5 4 5 6 5
出力例 2Copy
2
入力例 3Copy
100000 1 1 100000 100
出力例 3Copy
99999
Score : points
Problem Statement
There are cards placed face down in a row. On each card, an integer or is written.
Let be the integer written on the -th card.
Your objective is to guess correctly.
You know the following facts:
- For each , the value is an even number.
You are a magician and can use the following magic any number of times:
Magic: Choose one card and know the integer written on it. The cost of using this magic is .
What is the minimum cost required to determine all of ?
It is guaranteed that there is no contradiction in given input.
Constraints
- All values in input are integers.
- The pairs are distinct.
- There is no contradiction in input. (That is, there exist integers that satisfy the conditions.)
Input
Input is given from Standard Input in the following format:
Output
Print the minimum total cost required to determine all of .
Sample Input 1Copy
3 1 1 2 1
Sample Output 1Copy
2
You can determine all of by using the magic for the first and third cards.
Sample Input 2Copy
6 5 1 2 1 2 3 2 1 3 3 4 5 4 5 6 5
Sample Output 2Copy
2
Sample Input 3Copy
100000 1 1 100000 100
Sample Output 3Copy
99999