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. 初识跨终端Web

    近期试读了<跨终端Web>这本书的部分章节,既为了拿到书,也为了记录下读后的收获的东西,这会是个非常好的习惯吧. 标题为"初识跨终端Web".对我来说最贴切了,在此之前 ...

  2. sanic官方文档解析之streaming(流动,滚动)和class_based_views(CBV的写法)

    1,streaming(流媒体) 1.1请求流媒体 Sanic允许你通过流媒体携带请求数据,如下,当请求结束await request.stream.read()就会返回None,仅仅只有post请求 ...

  3. top load average

    负载均值 等待运行的进程数

  4. HDU 2746 Cyclic Nacklace

    Cyclic Nacklace Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  5. Delphi通过Get获取来自PHP的返回值

    Delphi代码 unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Contro ...

  6. django rest_framework swagger使用案例

    环境准备 环境要求: python3 django2 pip3 模块安装: pip3 install django-rest-framework pip3 install django-rest-sw ...

  7. POJ2195 Going Home —— 最大权匹配 or 最小费用最大流

    题目链接:https://vjudge.net/problem/POJ-2195 Going Home Time Limit: 1000MS   Memory Limit: 65536K Total ...

  8. 织梦CMS被挂马特征汇总

    一.织梦CMS被挂马特征汇总 2013织梦CMS被挂马特征汇总.最近很多朋友反应后台多了几个系统管理员用户:service.spider等,而且自己之前的管理员用户登陆时候会提示用户名不存在.还有朋友 ...

  9. 创建Android本地repo

    /**************************************************************************** * 创建Android本地repo * 说明 ...

  10. MyBatis学习 之 五、MyBatis配置文件

    在定义sqlSessionFactory时需要指定MyBatis主配置文件: <bean id="sqlSessionFactory" class="org.myb ...