Alice and Bob got very bored during a long car trip so they decided to play a game. From the window they can see cars of different colors running past them. Cars are going one after another.

The game rules are like this. Firstly Alice chooses some color A, then Bob chooses some color B (A ≠ B). After each car they update the number of cars of their chosen color that have run past them. Let's define this numbers after i-th car cntA(i) and cntB(i).

  • If cntA(i) > cntB(i) for every i then the winner is Alice.
  • If cntB(i) ≥ cntA(i) for every i then the winner is Bob.
  • Otherwise it's a draw.

Bob knows all the colors of cars that they will encounter and order of their appearance. Alice have already chosen her color A and Bob now wants to choose such color B that he will win the game (draw is not a win). Help him find this color.

If there are multiple solutions, print any of them. If there is no such color then print -1.

Input

The first line contains two integer numbers n and A (1 ≤ n ≤ 105, 1 ≤ A ≤ 106) – number of cars and the color chosen by Alice.

The second line contains n integer numbers c1, c2, ..., cn (1 ≤ ci ≤ 106) — colors of the cars that Alice and Bob will encounter in the order of their appearance.

Output

Output such color B (1 ≤ B ≤ 106) that if Bob chooses it then he will win the game. If there are multiple solutions, print any of them. If there is no such color then print -1.

It is guaranteed that if there exists any solution then there exists solution with (1 ≤ B ≤ 106).

Examples
input
4 1
2 1 4 2
output
2
input
5 2
2 2 4 5 3
output
-1
input
3 10
1 2 3
output
4
Note

Let's consider availability of colors in the first example:

  • cnt2(i) ≥ cnt1(i) for every i, and color 2 can be the answer.
  • cnt4(2) < cnt1(2), so color 4 isn't the winning one for Bob.
  • All the other colors also have cntj(2) < cnt1(2), thus they are not available.

In the third example every color is acceptable except for 10.

题意:两个人玩游戏,额,两个人分别选一个数字,现在我们让B赢,规则是

当前位置上,所选的数字比另外一个选的数字出现次数多或者一样就算这个位置胜利了,从头到尾一直是B胜利就行

比如 2 1 4 2   A选了1 B选2

2在第一位出现一次,1没有出现,第一位胜利

2在第二位没有出现,1出现一次,一共是1:1,也是胜利

第三位两个数字都没有,1:1,胜利

第四位2出现,最后是2:1 胜利

解法:

1 必输的情况,A把第一个数字选了

2 必胜的情况,A没有选C数组任何一个,那么我们随便选一个就行

3 如果某一个数字曾经输于A,则不选

比如 A选2

3 2 2 2 3  那么3输了,不能选3

4 B不能选和A相同的数字,且出现次数比A选的数字要多。经过第3点的过滤,出现符合第4点的数字立马输出就行

 #include<bits/stdc++.h>
using namespace std;
const long long N = 1e6+;
vector<long long>v[];
set<int>P;
long long A[N];
map<int,int>Q,Mp;
int main()
{
int num,a;
int flag=;
scanf("%d%d",&num,&a); for(int i=;i<=num;i++){
scanf("%d",&A[i]); if(A[i]==a){
flag=;
}
if(Q[A[i]]<Q[a]){
Mp[A[i]]=-;
}
Q[A[i]]++;
}
if(A[]==a){
printf("-1");
return ;
}
if(flag==){
for(int i=;i<N;i++){
if(Q[A[i]]>=Q[a]&&Mp[A[i]]!=-&&A[i]!=a){
printf("%d",A[i]);
return ;
}
}
printf("-1");
return ; }else{
printf("%d",A[]);
}
return ;
}

Educational Codeforces Round 24 D的更多相关文章

  1. Educational Codeforces Round 24 A 水 B stl C 暴力 D stl模拟 E 二分

    A. Diplomas and Certificates time limit per test 1 second memory limit per test 256 megabytes input ...

  2. Educational Codeforces Round 24 CF 818 A-G 补题

    6月快要结束了 期末也过去大半了 马上就是大三狗了 取消了小学期后20周的学期真心长, 看着各种北方的学校都放假嗨皮了,我们这个在北回归线的学校,还在忍受酷暑. 过年的时候下定决心要拿块ACM的牌子, ...

  3. Educational Codeforces Round 24 E

    Vova again tries to play some computer card game. The rules of deck creation in this game are simple ...

  4. codeforces Educational Codeforces Round 24 (A~F)

    题目链接:http://codeforces.com/contest/818 A. Diplomas and Certificates 题解:水题 #include <iostream> ...

  5. Educational Codeforces Round 24

    A. Diplomas and Certificates time limit per test 1 second memory limit per test 256 megabytes input ...

  6. Educational Codeforces Round 24 B

    n children are standing in a circle and playing a game. Children's numbers in clockwise order form a ...

  7. Educational Codeforces Round 24 A

    There are n students who have taken part in an olympiad. Now it's time to award the students. Some o ...

  8. Educational Codeforces Round 24 题解

    A: 考你会不会除法 //By SiriusRen #include <bits/stdc++.h> using namespace std; #define int long long ...

  9. Educational Codeforces Round 32

    http://codeforces.com/contest/888 A Local Extrema[水] [题意]:计算极值点个数 [分析]:除了第一个最后一个外,遇到极值点ans++,包括极大和极小 ...

随机推荐

  1. Android_Service详解及实例

    转自:http://blog.csdn.net/guolin_blog/article/details/11952435    http://blog.csdn.net/guolin_blog/art ...

  2. VC断点失败的原因之中的一个

    VC断点失败的原因之中的一个 flyfish 2014-10-23 情景 再debug状态下仅仅有一个cpp文件.命中不了断点. 提示 能够 同意源码与原始版本号不同 不採用,防止出现未知的隐患 问题 ...

  3. ssh免密码访问

    ssh-copy-id命令 它可以把本地主机的公钥复制到远程主机的authorized_keys文件上,ssh-copy-id命令也会给远程主机的用户主目录(home)和~/.ssh, 和~/.ssh ...

  4. all rows from client_id can grow infinitely compared to a single node when hashing by client_id

    all rows from client_id can grow infinitely compared to a single node when hashing by client_id Re: ...

  5. 恢复MySQL数据库删除的数据

    在日常运维工作中,对于数据库的备份是至关重要的!数据库对于网站的重要性使得我们对 MySQL 数据库的管理不容有失!然而是人总难免会犯错误,说不定哪天大脑短路了,误操作把数据库给删除了,怎么办? 下面 ...

  6. Hadoop MapReduce基本原理

    一.什么是: MapReduce是一种编程模型,用于大规模数据集(大于1TB)的并行运算.概念"Map(映射)"和"Reduce(归约)",是它们的主要思想,都 ...

  7. Vue中 key keep-alive

    keep-alive key <!DOCTYPE html> <html> <head> <title></title> <scrip ...

  8. [Silverlight 2.0 控制物体绕圆弧运行(C#初探篇)]

    我自己写的第一个 Silverlight 2.0 程序    [Silverlight 2.0 控制物体绕圆弧运行(C#初探篇)]            程序运行时:小地球将绕着圆形轨迹做圆周运动. ...

  9. [Java] String类, StringBuffer类

    1. String 类 1. 创建: String s1 = new String; s1 = "abc"; String s2 = new String("abc&qu ...

  10. Open multiple excel files in WebBrowser, only the last one gets activated

    http://stackoverflow.com/questions/20578053/open-multiple-excel-files-in-webbrowser-only-the-last-on ...