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

The first line contains integer n (1 ≤ n ≤ 103) — the number of secretaries in Polycarpus's corporation. The next line contains n space-separated integers: id1, id2, ..., idn (0 ≤ idi ≤ 109). Number idi equals the number of the call session of the i-th secretary, if the secretary is talking via Spyke, or zero otherwise.

Consider the secretaries indexed from 1 to n in some way.

Output

Print a single integer — the number of pairs of chatting secretaries, or -1 if Polycarpus's got a mistake in his records and the described situation could not have taken place.

Examples

Input

6
0 1 7 1 7 10

Output

2

Input

3
1 1 1

Output

-1

Input

1
0

Output

0

Note

In the first test sample there are two Spyke calls between secretaries: secretary 2 and secretary 4, secretary 3 and secretary 5.

In the second test sample the described situation is impossible as conferences aren't allowed.

解题思路:题目的意思就是从n个数字中找出m对相同的数字(不为0),即该数出现的次数刚好为2次,此时输出m;如果该数字出现的次数超过2次,输出-1;没有的话输出0,简单水过。

AC代码:

 #include<bits/stdc++.h>
using namespace std;
const int maxn=;
struct NODE{
int data,num;
}node[maxn];
int main(){
int n,x,k=,m=;bool flag0,flag1=false;
cin>>n;
for(int i=;i<maxn;++i)node[i].num=;
for(int i=;i<=n;++i){
cin>>x;flag0=false;
if(x!=){//去掉0
for(int j=;j<k;++j)
if(node[j].data==x){node[j].num++;flag0=true;break;}
if(!flag0){node[k].num++;node[k++].data=x;}
}
}
for(int i=;i<k;++i){
if(node[i].num==)m++;
if(node[i].num>){flag1=true;break;}//只要有相同数字超过2,即为-1
}
if(flag1)cout<<"-1"<<endl;
else if(m) cout<<m<<endl;
else cout<<''<<endl;
return ;
}

最新文章

  1. ucos实时操作系统学习笔记——任务间通信(互斥锁)
  2. C# 知识特性 Attribute
  3. JavaScript中的枚举
  4. (转)T-SQL查询处理执行顺序(一)
  5. FTP\TFTP
  6. Wordpress模板标签大全
  7. JCIFS是很不稳定的
  8. Spring.Net+NHibernate+asp.net mvc + easyui
  9. mongodb的 或 查询,实践总结
  10. centos6.5安装nodejs
  11. MyEclipse中用Maven创建Web项目
  12. 19. leetcode 100. Same Tree
  13. System.Web.Mvc 3.0.0.1 和 3.0.0.0 有什么区别?被 Microsoft ASP.NET MVC 的一次安全更新害惨了!!!
  14. GoLang-Beego使用
  15. 导入numpy时,出错怎么解决?
  16. Rigidbody.Is Kinematic和碰撞体
  17. 源码安装svn 1.8.9
  18. Eclipse远程连接Hadoop
  19. 利用jquery.backstretch插件,背景切换
  20. 点击文字,把input type=&quot;radio&quot;也选中

热门文章

  1. MVC 运行视图出错
  2. HTML 1.1页面js修改文字颜色
  3. 【剑指Offer】40、数组中只出现一次的数字
  4. buildroot的make menuconfig配置
  5. 获取url
  6. HDU1087 - Super Jumping! Jumping! Jumping!【动态规划】
  7. windows环境下用pip安装pyautogui遇到的几个问题
  8. setTimeout(fn,0)的作用分析
  9. tomcat日志采集
  10. _DataStructure_C_Impl:求图G中从顶点u到顶点v的一条简单路径