【CF 1143A】The Doors

                                          A. The Doors

Three years have passes and nothing changed. It is still raining in London, and Mr. Black has to close all the doors in his home in order to not be flooded. Once, however, Mr. Black became so nervous that he opened one door, then another, then one more and so on until he opened all the doors in his house.

There are exactly two exits from Mr. Black's house, let's name them left and right exits. There are several doors in each of the exits, so each door in Mr. Black's house is located either in the left or in the right exit. You know where each door is located. Initially all the doors are closed. Mr. Black can exit the house if and only if all doors in at least one of the exits is open. You are given a sequence in which Mr. Black opened the doors, please find the smallest index kk such that Mr. Black can exit the house after opening the first kk doors.

We have to note that Mr. Black opened each door at most once, and in the end all doors became open.

Input

The first line contains integer nn (2≤n≤2000002≤n≤200000) — the number of doors.

The next line contains nn integers: the sequence in which Mr. Black opened the doors. The ii-th of these integers is equal to 00 in case the ii-th opened door is located in the left exit, and it is equal to 11 in case it is in the right exit.

It is guaranteed that there is at least one door located in the left exit and there is at least one door located in the right exit.

Output

Print the smallest integer kk such that after Mr. Black opened the first kk doors, he was able to exit the house.

Examples

input

5
0 0 1 0 0

output

3

input

4
1 0 0 1

output

3

题意:

n扇门,左边的门编号为0,右边的门编号为1,初始n个门都是关闭的,给出序列n,依次关闭左右的门,求关到第几个门的时候所有左边或右边的门都关闭了

代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define mem(a,b) memset(a,b,sizeof(a))

int a[200005];

int main()
{
	int n,m,i,x=0,y=0;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
		if(a[i]==0)
			x++;
		else
			y++;
	}
	for(i=1;i<=n;i++)
	{
		if(a[i]==0)
			x--;
		else
			y--;
		if(x==0||y==0)
		{
			cout<<i<<endl;
			break;
		}
	}
	return 0;
}

 

全部评论

相关推荐

点赞 评论 收藏
分享
当初高考报计算机真是造大孽了啊!卷的飞起!哪都是计算机的人,考研,考公,找工作全他奶的计算机的人,太难了。国企也是。关键一届比一届卷,造大孽了!
_Lyrics_:因为计算机,没有体验到快乐的大学研究生时光,好不容易修完课程就要出去实习,看着别人专业可以一起搓麻将,游山玩水,而我却要自己一个人住在北上不到十平米的出租屋,每天两点一线
点赞 评论 收藏
分享
嵌入式求职之路:可以看我经验😂,https://www.nowcoder.com/share/jump/73221730841876945
点赞 评论 收藏
分享
在debug的柠檬精很迷人:好消息:现在HR挑三拣四 15年后 HR跪着求要简历 坏消息:被挑的是这代人,到时候求人的也是这代人。真好。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务