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 ;
}

B - Spyke Talks的更多相关文章

  1. myeclispe启动后报错 Subclipse talks to Subversion via a Java API that requires access to native libraries.

    myeclispe 中SVN插件常遇到的异常: Subclipse talks to Subversion via a Java API that requires access to native ...

  2. 100 Most Popular Machine Learning Video Talks

    100 Most Popular Machine Learning Video Talks 26971 views, 1:00:45,  Gaussian Process Basics, David ...

  3. VK Cup 2012 Qualification Round 1 E. Phone Talks —— DP

    题目链接:http://codeforces.com/contest/158/problem/E E. Phone Talks time limit per test 3 seconds memory ...

  4. Takin Talks·上海 |开源后首场主题研讨会来了,一起解密Takin技术吧!

      自 6 月 25 日全球首款生产环境全链路压测平台 Takin 正式开源,短短 13 天时间,Github 主页上 Star 数已超过 730,开发者社群也积累了 1500+粉丝.群内技术研讨氛围 ...

  5. Codeforces 158E Phone Talks

    http://codeforces.com/contest/158/problem/E 题目大意: 麦克是个名人每天都要接n电话,每通电话给出打来的时间和持续时间,麦克可以选择接或不接,但是只能不接k ...

  6. (zhuan) Some Talks about Dual Learning

    研究|对偶学习:一种新的机器学习范式  this blog copy from: http://www.msra.cn/zh-cn/news/blogs/2016/12/dual-learning-2 ...

  7. Book Contents Reviews Notes Errata Articles Talks Downloads Resources Code Formatter Cover of C# in Depth Order now (3rd edition) Implementing the Singleton Pattern in C#

    原文链接地址: http://csharpindepth.com/Articles/General/Singleton.aspx#unsafe Implementing the Singleton P ...

  8. myeclispe2014启动后报错 Subclipse talks to Subversion via a Java API that requires access to native libraries.

    解决方案: Window -> Preferences -> Team -> SVN, 将SVN接口的Client修改为如图所示

  9. Codeforces 158E Phone Talks:dp

    题目链接:http://codeforces.com/problemset/problem/158/E 题意: 你有n个电话要接,每个电话打进来的时刻为第t[i]分钟,时长为d[i]分钟. 每一个电话 ...

随机推荐

  1. JAVA软件工程师应该具备哪些基本素质?

    必知:软件企业要求基础软件工程师具备六大基本素质,即良好的编码能力.自觉的规范意识和团队精神.认识和运用数据库的能力.较强的英语阅读和写作能力.具有软件工程的概念和求知欲和进取心. 1.良好的编码能力 ...

  2. 微信jssdk图片上传

    一.html页面如下: <div class="weui-cell"> <div class="weui-cell__hd"></ ...

  3. CentOS6.9下NFS配置说明

    NFS是Network File System的缩写,即网络文件系统.它的主要功能是通过网络(一般是局域网)让不同的主机系统之间可以共享文件或目录.NFS客户端可以通过挂载(mount)的方式将NFS ...

  4. esp32使iOS 获取蓝牙外设的Mac地址

    最近在做一个需要上下位机的项目,我负责的任务下位机,使用的主控芯片是esp32.这个项目中有一项是需要手机扫描二维码然后连接作为esp32的蓝牙.二维码中包含了mac地址信息,在手机扫描周围设备的时候 ...

  5. python 遍历xml所有节点

    1.xml文件 2.代码 #coding:utf-8 import xml import xml.etree.ElementTree as ET """ 实现从xml文件 ...

  6. Codeforces Round #548 (Div. 2) B. Chocolates

    You went to the store, selling 

  7. 【习题 4-7 UVA - 509】RAID!

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 如果一行里面某位有>1个x 那么是invalid的. 没有x的话. 可以分析以下(设输入的标准Even为0,然后Odd为1) ...

  8. 使用idea搭建maven项目时 java目录下的xml文件没有加载的解决方法

    今天在idea集成开发环境下 使用maven搭建了ssm项目,遇到了3个问题 首先我们先复习一下知识点: 第一步:在web.xml中配置spring监听器 <!-- spring监听器 加载sp ...

  9. 第三次训练 密码acmore

    网站:CSUST7月23号 A题:大意是:一个N多边形,用红,绿,蓝三色给定点上色,要求划分成顶点颜色不同的三角形. 解析: 这道题是黑书上分治法的例题,还是比较巧的. 首先很容易发现当某种颜色的点只 ...

  10. hdu 1245 Saving James Bond 策画几何+最短路 最短路求步数最少的路径

    #include<stdio.h> #include<string.h> #include<math.h> #define inf 0x3fffffff #defi ...