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. linux块设备驱动(一)——块设备概念介绍

    本文来源于: 1. http://blog.csdn.net/jianchi88/article/details/7212370 2. http://blog.chinaunix.net/uid-27 ...

  2. ssh原理【转】

    1 转自 http://www.ruanyifeng.com/blog/2011/12/ssh_remote_login.html 2 ssh远程登陆的原理 普通用户远程登陆 ssh jason@ho ...

  3. 关闭mongodb 集群

    [root@hadoop1 ~]# ps -aux | grep mongodb; root ? Sl : : /usr/local/mongodb/bin/mongod -f /usr/local/ ...

  4. HTML5 and Websocket

    在HTML5规范中,我最喜欢的Web技术就是正迅速变得流行的WebSocket API.WebSocket提供了一个受欢迎的技术,以替代我们过去几年一直在用的Ajax技术.这个新的API提供了一个方法 ...

  5. C++的学习 (此博客将一直补充更新下去,C++语法方面的内容不开新随笔了, *【语法学习】)

    // #include <sstream> // stringstream 是 C++ 提供的另一个字串型的串流(stream)物件,包含在上述头文件中 // 先谈它在字符串处理方面的应用 ...

  6. JS判断按时间跳转到相应的页面

    <!--时间段跳转js--><script language="javaScript" type="text/javascript"> ...

  7. nginx网站日志配置

    用yum安装的nginx的日志默认安装在路径:/var/log/nginx nginx配置文件:/etc/nginx/nginx.conf (总配置文件)/etc/nginx/conf.d/defau ...

  8. php中自运算++ 或-- 的总结

    <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...

  9. 推箱子 Sokoban(华中农业比赛)

    点这里 打开题目链接   点击打开链接 题目就是我们玩过的推箱子: 一顿暴力广搜:加状态标记.状态压缩需要用到一个类似于康拓的思想来压缩:所以容易TLE,搜索就是用一个int型的数字来表示一个状态, ...

  10. 默认action和ActionSupport

    默认action: <action></action>中的name属性值与<default-action-ref></default-action-ref&g ...