Banner Home Page Web Contests Problems Ranklist Status Statistics

A. Spyke Talks

Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 524288/262144K (Java/Other)
Total Submission(s) : 0   Accepted Submission(s) : 0
Problem Description

Polycarpus is the director of a large corporation. There are n secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each other via Spyke, the Spyke network assigns a unique ID to this call, a positive integer session number.

One day Polycarpus wondered which secretaries are talking via the Spyke and which are not. For each secretary, he wrote out either the session number of his call or a 0 if this secretary wasn't talking via Spyke at that moment.

Help Polycarpus analyze these data and find out the number of pairs of secretaries that are talking. If Polycarpus has made a mistake in the data and the described situation could not have taken place, say so.

Note that the secretaries can correspond via Spyke not only with each other, but also with the people from other places. Also, Spyke conferences aren't permitted that is, one call connects exactly two people.

 

Input
<p>The first line contains integer <span class="tex-span"><i>n</i></span> <span class="tex-span">(1¡Ü<i>n</i>¡Ü10<sup class="upper-index">3</sup>)</span> the number of secretaries in Polycarpus's corporation. The next line contains <span class="tex-span"><i>n</i></span> space-separated integers: <span class="tex-span"><i>id</i><sub class="lower-index">1</sub>,<i>id</i><sub class="lower-index">2</sub>,...,<i>id</i><sub class="lower-index"><i>n</i></sub></span> <span class="tex-span">(0¡Ü<i>id</i><sub class="lower-index"><i>i</i></sub>¡Ü10<sup class="upper-index">9</sup>)</span>. Number <span class="tex-span"><i>id</i><sub class="lower-index"><i>i</i></sub></span> equals the number of the call session of the <span class="tex-span"><i>i</i></span>-th secretary, if the secretary is talking via Spyke, or zero otherwise.</p><p>Consider the secretaries indexed from 1 to <span class="tex-span"><i>n</i></span> in some way.</p>
 

Output
<p>Print a single integer the number of pairs of chatting secretaries, or <span class="tex-font-style-tt">-1</span> if Polycarpus's got a mistake in his records and the described situation could not have taken place.</p>
 

Sample Input
6 0 1 7 1 7 10 3 1 1 1
 

Sample Output
2 -1
 

Source
Codeforces
 

Statistic | Submit | Back