#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <string>
#include <algorithm>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include<cstdlib>
#include <map>
#include <utility>
using namespace std;
//259774TG

typedef long long ll;
typedef long double ld;

#define all(v) v.begin(),v.end()

const long double pi = 3.1415926535;

bool check(char c) {
	return (c <= 'z' && c >= 'a') || (c <= 'Z' && c >= 'A');
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	else return gcd(b, a%b);
}

bool IsPrime(ll n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0) return false;
	}
	return true;
}

bool cont(string s, string t) {
	int j = 0;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == t[j]) {
			j++;
		}
		if (j == t.length()) return true;
	}
	return false;
}

int main() {

	int t;
	cin >> t;
	while (t--) {
		ll n, m, k;
		cin >> n >> m >> k;
		vector<int> v(n);
		for (int i = 0; i < n; i++) {
			cin >> v[i];
		}
		bool ch = false;
		for (int i = 0; i < n - 1; i++) {
			if (v[i] < v[i + 1] && v[i+1]-v[i]<=k) {
				m += v[i]-(v[i+1]-k);

			}
			else if (v[i] < v[i + 1] && v[i+1]-v[i]>k) {
				m -= v[i + 1] - v[i];

			}
			else if(v[i]>=v[i+1]) {
				m += v[i] - v[i + 1];
				if (v[i + 1] >= k) m += k;
				else m += v[i + 1];

			}
			if (m < 0) {
				ch = true;
				break;
			}

		}

		if (ch) {
			cout << "NO" << endl;
		}
		else cout << "YES" << endl;

	}
}


#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <string>
#include <algorithm>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include<cstdlib>
#include <map>
#include <utility>
using namespace std;
//259774TG

typedef long long ll;
typedef long double ld;

#define all(v) v.begin(),v.end()

const long double pi = 3.1415926535;

bool check(char c) {
	return (c <= 'z' && c >= 'a') || (c <= 'Z' && c >= 'A');
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	else return gcd(b, a%b);
}

bool IsPrime(ll n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0) return false;
	}
	return true;
}

bool cont(string s, string t) {
	int j = 0;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == t[j]) {
			j++;
		}
		if (j == t.length()) return true;
	}
	return false;
}

int main() {

	int t;
	cin >> t;
	while (t--) {
		ll n, m, k;
		cin >> n >> m >> k;
		vector<int> v(n);
		for (int i = 0; i < n; i++) {
			cin >> v[i];
		}
		bool ch = false;
		for (int i = 0; i < n - 1; i++) {
			if (v[i] < v[i + 1] && v[i+1]-v[i]<=k) {

				if(v[i+1]>=k)
				m += v[i]-(v[i+1]-k);
				else m += v[i];

			}
			else if (v[i] < v[i + 1] && v[i+1]-v[i]>k) {
				m -= v[i + 1] - k - v[i];

			}
			else if(v[i]>=v[i+1]) {
				m += v[i] - v[i + 1];
				if (v[i + 1] >= k) m += k;
				else m += v[i + 1];

			}
			if (m < 0) {
				ch = true;
				break;
			}

		}

		if (ch) {
			cout << "NO" << endl;
		}
		else cout << "YES" << endl;

	}
}


#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <string>
#include <algorithm>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include<cstdlib>
#include <map>
#include <utility>
using namespace std;
//259774TG

typedef long long ll;
typedef long double ld;

#define all(v) v.begin(),v.end()

const long double pi = 3.1415926535;

bool check(char c) {
	return (c <= 'z' && c >= 'a') || (c <= 'Z' && c >= 'A');
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	else return gcd(b, a%b);
}

bool IsPrime(ll n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0) return false;
	}
	return true;
}

bool cont(string s, string t) {
	int j = 0;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == t[j]) {
			j++;
		}
		if (j == t.length()) return true;
	}
	return false;
}

int main() {

	int t;
	cin >> t;
	while (t--) {
		ll n, m, k;
		cin >> n >> m >> k;
		vector<int> v(n);
		for (int i = 0; i < n; i++) {
			cin >> v[i];
		}
		bool ch = false;
		for (int i = 0; i < n - 1; i++) {
			if (v[i] < v[i + 1] && v[i+1]-v[i]<=k) {
				m += v[i]-(v[i+1]-k);

			}
			else if (v[i] < v[i + 1] && v[i+1]-v[i]>k) {
				m -= v[i + 1] - v[i];

			}
			else if(v[i]>=v[i+1]) {
				m += v[i] - v[i + 1] + k;

			}
			if (m < 0) {
				ch = true;
				break;
			}

		}

		if (ch) {
			cout << "NO" << endl;
		}
		else cout << "YES" << endl;

	}
}


#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <string>
#include <algorithm>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include<cstdlib>
#include <map>
#include <utility>
using namespace std;
//259774TG

typedef long long ll;
typedef long double ld;

#define all(v) v.begin(),v.end()

const long double pi = 3.1415926535;

bool check(char c) {
	return (c <= 'z' && c >= 'a') || (c <= 'Z' && c >= 'A');
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	else return gcd(b, a%b);
}

bool IsPrime(ll n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0) return false;
	}
	return true;
}

bool cont(string s, string t) {
	int j = 0;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == t[j]) {
			j++;
		}
		if (j == t.length()) return true;
	}
	return false;
}

int main() {

	int t;
	cin >> t;
	while (t--) {
		ll n, m, k;
		cin >> n >> m >> k;
		vector<int> v(n);
		for (int i = 0; i < n; i++) {
			cin >> v[i];
		}
		bool ch = false;
		for (int i = 0; i < n - 1; i++) {
			if (v[i] < v[i + 1] && v[i+1]-v[i]<=k) {
				m += v[i]-(v[i+1]-k);

			}
			else if (v[i] < v[i + 1] && v[i+1]-v[i]>k) {
				m -= v[i + 1] - k - v[i];

			}
			else if(v[i]>=v[i+1]) {
				m += v[i] - v[i + 1];
				if (v[i + 1] >= k) m += k;
				else m += v[i + 1];

			}
			if (m < 0) {
				ch = true;
				break;
			}

		}

		if (ch) {
			cout << "NO" << endl;
		}
		else cout << "YES" << endl;

	}
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int T; cin >> T;
	while (T--)
	{
		int n, m, k;//n是有多少个柱，m是背包的方块数，k是高度差
		int a[105];
		bool flag = true;
		cin >> n >> m >> k;
		for (int i = 1; i <= n; ++i) cin >> a[i];
		for (int i = 1; i <= n; ++i)
		{
			if (a[i] < a[i + 1] - k)
			{
				m -= (a[i + 1] - k - a[i]);
				if (m < 0) { cout << "NO\n"; flag = false; break; }
			}
			if (a[i] == a[i + 1] - k) continue;
			if (a[i] > a[i + 1] - k)
			{
				m += min(a[i], a[i] - a[i + 1] + k);
			}
		}
		if (flag) cout << "YES\n";
	}
	//system("pause");
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int T; cin >> T;
	while (T--)
	{
		long long int n, m, k;//n是有多少个柱，m是背包的方块数，k是高度差
		long long int a[105];
		bool flag = true;
		cin >> n >> m >> k;
		for (int i = 1; i <= n; ++i) cin >> a[i];
		for (int i = 1; i <= n; ++i)
		{
			if (a[i] < a[i + 1] - k)
			{
				m -= (a[i + 1] - k - a[i]);
				if (m < 0) { cout << "NO\n"; flag = false; break; }
			}
			if (a[i] == a[i + 1] - k) continue;
			if (a[i] > a[i + 1] - k)
			{
				m += min(a[i], a[i] - a[i + 1] + k);
			}
		}
		if (flag) cout << "YES\n";
	}
	//system("pause");
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int T; cin >> T;
	while (T--)
	{
		long long int n, m, k;//n是有多少个柱，m是背包的方块数，k是高度差
		long long int a[105];
		bool flag = true;
		cin >> n >> m >> k;
		for (int i = 1; i <= n; ++i) cin >> a[i];
		for (int i = 1; i < n; ++i)
		{
			if (a[i] < a[i + 1] - k)
			{
				m -= (a[i + 1] - k - a[i]);
				if (m < 0) { cout << "NO\n"; flag = false; break; }
				continue;
			}
			if (a[i] == a[i + 1] - k) continue;
			if (a[i] > a[i + 1] - k)
			{
				m += min(a[i], a[i] - a[i + 1] + k);
			}
		}
		if (flag) cout << "YES\n";
	}
	//system("pause");
}


#include <iostream>
#include <vector>
#include <bitset>
using namespace std;

int T, n, m, K;
int i;
int cols[101];
int main() {
	cin.tie(NULL);
	cout.tie(NULL);
	ios::sync_with_stdio(false);

	cin >> T;
	while (T--) {
		cin >> n >> m >> K;
		for (i = 0; i < n; i++)
			cin >> cols[i];

		if (n == 1) {
			cout << "YES" << '\n';
			continue;
		}

		for (i = 0; i < n-1; i++) {
			int diff = cols[i+1] - cols[i];
			if (diff <= K && diff >= 0)
				m += (K - diff);
			else if (diff > K + m) {
				cout << "NO" << '\n';
				break;
			}
			else if (diff < 0) {
				cols[i] += 2*diff;
				m -= 2 * diff;
				if (cols[i] < 0) {
					m += cols[i];
					cols[i] = 0;
				}
			}
			else {
				m -= diff - K;
				cols[i] = cols[i + 1] - K;
			}

			if (i == n - 2)
				cout << "YES" << '\n';
		}

	}
	return 0;
}


#include <iostream>
#include <vector>
#include <bitset>
using namespace std;

int T, n, m, K;
int i;
int col[101];
int main() {
	cin.tie(NULL);
	cout.tie(NULL);
	ios::sync_with_stdio(false);

	cin >> T;
	while (T--) {
		cin >> n >> m >> K;
		for (i = 0; i < n; i++)
			cin >> col[i];

		if (n == 1) {
			cout << "YES" << '\n';
			continue;
		}

		for (i = 0; i < n-1; i++) {
			int diff = col[i + 1] - col[i];
			if (diff >= 0) {
				if (diff - K > m) {
					cout << "NO" << '\n';
					break;
				}
				else if(diff-K <=m && diff-K>=0) {
					m -= (diff - K);
					col[i] += (diff - K);
				}
				else if (diff - K < 0) {
					int get = K-diff;
					col[i] -= get;
					m += get;
					if (col[i] < 0) {
						m += col[i];
						col[i] = 0;
					}
				}
			}
			else if (diff < 0) {
				m += -diff;
				col[i] += diff;
				m += K;
				col[i] -= K;
				if (col[i] < 0) {
					m += col[i];
					col[i] = 0;
				}
			}

			if (i == n - 2)
				cout << "YES" << '\n';
		}

	}
	return 0;
}


#include <iostream>
#include <vector>
#include <bitset>
using namespace std;

int T, n, m, K;
int i;
int cols[101];
int main() {
	cin.tie(NULL);
	cout.tie(NULL);
	ios::sync_with_stdio(false);

	cin >> T;
	while (T--) {
		cin >> n >> m >> K;
		for (i = 0; i < n; i++)
			cin >> cols[i];

		if (n == 1) {
			cout << "YES" << '\n';
			continue;
		}

		for (i = 0; i < n-1; i++) {
			int diff = cols[i+1] - cols[i];
			if (diff <= K && diff >= 0) {
				m += (K - diff);
				cols[i] -= (K - diff);
				if (cols[i] < 0) {
					m += cols[i];
					cols[i] = 0;
				}

			}
			else if (diff > K + m) {
				cout << "NO" << '\n';
				break;
			}
			else if (diff < 0) {
				cols[i] += 2*diff;
				m -= 2 * diff;
				if (cols[i] < 0) {
					m += cols[i];
					cols[i] = 0;
				}
			}
			else {
				m -= diff - K;
				cols[i] = cols[i + 1] - K;
			}

			if (i == n - 2)
				cout << "YES" << '\n';
		}

	}
	return 0;
}


#include <iostream>
#include <vector>
#include <bitset>
using namespace std;

int T, n, m, K;
int i;
int col[101];
int main() {
	cin.tie(NULL);
	cout.tie(NULL);
	ios::sync_with_stdio(false);

	cin >> T;
	while (T--) {
		cin >> n >> m >> K;
		for (i = 0; i < n; i++)
			cin >> col[i];

		if (n == 1) {
			cout << "YES" << '\n';
			continue;
		}

		for (i = 0; i < n-1; i++) {
			int diff = col[i + 1] - col[i];
			if (diff >= 0) {
				if (diff - K > m) {
					cout << "NO" << '\n';
					break;
				}
				else if(diff-K <=m && diff-K>=0) {
					m -= (diff - K);
				}
				else if (diff - K < 0) {
					int get = K-diff;
					col[i] -= get;
					m += get;
					if (col[i] < 0) {
						m += col[i];
						col[i] = 0;
					}
				}
			}
			else if (diff < 0) {
				m += -diff;
				col[i] -= diff;

				m += K;
				col[i] -= K;

				if (col[i] < 0) {
					m += col[i];
					col[i] = 0;
				}
			}

			if (i == n - 2)
				cout << "YES" << '\n';
		}

	}
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
using namespace std;

void outVector(vector<int>& a) {
	for (int i = 0; i < a.size(); i++) {
		cout << a[i] << " ";
	}
	cout << "\n";
}

int main() {
	int t;
	cin >> t;
	for (int iter = 0; iter < t; iter++) {
		int n, b, k;
		cin >> n >> b >> k;
		vector<int> s(n);
		for (int i = 0; i < n; i++)
			cin >> s[i];
		for (int i = 0; i < n - 1; i++) {
			if (s[i] >= s[i + 1])
				b += s[i] - s[i + 1] + k;
			else if (s[i] + k >= s[i + 1])
				b += k - (s[i + 1] - s[i]);
			else {
				b -= s[i + 1] - s[i] - k;
			}
		}
		if (b >= 0)
			cout << "YES\n";
		else
			cout << "NO\n";
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
using namespace std;

void outVector(vector<int>& a) {
	for (int i = 0; i < a.size(); i++) {
		cout << a[i] << " ";
	}
	cout << "\n";
}

int min(int a, int b) {
	if (a < b)
		return a;
	return b;
}

int main() {
	int t;
	cin >> t;
	for (int iter = 0; iter < t; iter++) {
		long long n, b, k;
		cin >> n >> b >> k;
		vector<long long> s(n);
		for (int i = 0; i < n; i++)
			cin >> s[i];
		for (int i = 0; i < n - 1; i++) {
			if (s[i] >= s[i + 1]) {
				b += s[i] - s[i + 1] + min(k, s[i + 1]);
				//cout << b << " from upper\n";
			}
			else if (s[i] + k >= s[i + 1]) {
				b += min(k, s[i + 1]) - (s[i + 1] - s[i]);
				//cout << b << " from the bottom\n";
			}
			else {
				b -= s[i + 1] - s[i] - k;
				//cout << b << " build\n";
				if (b < 0)
					break;
				//cout << b << " build\n";
			}
		}
		if (b >= 0)
			cout << "YES\n";
		else
			cout << "NO\n";
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
using namespace std;

void outVector(vector<int>& a) {
	for (int i = 0; i < a.size(); i++) {
		cout << a[i] << " ";
	}
	cout << "\n";
}

int main() {
	int t;
	cin >> t;
	for (int iter = 0; iter < t; iter++) {
		long long n, b, k;
		cin >> n >> b >> k;
		vector<long long> s(n);
		for (int i = 0; i < n; i++)
			cin >> s[i];
		for (int i = 0; i < n - 1; i++) {
			if (s[i] >= s[i + 1]) {
				b += s[i] - s[i + 1] + k;
				//cout << b << " from upper\n";
			}
			else if (s[i] + k >= s[i + 1]) {
				b += k - (s[i + 1] - s[i]);
				//cout << b << " from the bottom\n";
			}
			else {
				b -= s[i + 1] - s[i] - k;
				if (b < 0)
					break;
				//cout << b << " build\n";
			}
		}
		if (b >= 0)
			cout << "YES\n";
		else
			cout << "NO\n";
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

    int ajtok[200100];
int main()
{

    int n;
    cin >> n;

    int k, v;

    for (int i=0; i<n; i++){
        cin >> ajtok[i];
    }
    for (int i=0; i<n; i++){
        k=0;
        int j=i+1;
        while (k<1 && 1+j<n){
        j++;
        if (ajtok[i+1]!=ajtok[j]) k++;
        }
        if (k==0) {v=i+1;
        cout << v;
        return 0;}
    }
   return 0;
}


#include <bits/stdc++.h>

using namespace std;

    int ajtok[200100];
int main()
{

    int n;
    cin >> n;

    int utolso, valasz;
    for (int i=0; i<n; i++){
        cin >> ajtok[i];
    }
    utolso=ajtok[n-1];
    for (int i=0; i<n; i++){
        if (ajtok[i]!=utolso) valasz=i+1;
    }
    cout << valasz;
   return 0;
}


#include <bits/stdc++.h>

using namespace std;

int a[100005];

int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    int aa=0,bb=0;
    for(int i=n;i>=1;i--)
    {
        if(a[i]==0&&!aa)aa=i;
        if(a[i]==1&&!bb)bb=i;
    }
    cout<<min(aa,bb)<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int a[100005];

int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    int ans=1;
    for(int i=1;i<=n;i++)
    {
        if(a[i]!=a[i-1])ans++;
    }
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int a[100005];

int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    int ans=1;
    for(int i=2;i<=n;i++)
    {
        if(a[i]!=a[i-1])ans++;
    }
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int a[1000005];

int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    int aa=0,bb=0;
    for(int i=n;i>=1;i--)
    {
        if(a[i]==0&&!aa)aa=i;
        if(a[i]==1&&!bb)bb=i;
    }
    cout<<min(aa,bb)<<endl;
    return 0;
}


//code in cpp
#include <bits/stdc++.h>
#define int long long
#define mod  1000000007
using namespace std;
signed main()
{
    int n ;
    cin >> n ;
    vector<int>a(n);
    for(int i = 0 ; i < n ; i++)
    {
        cin>>a[i];
    }
    int left= 0 , right = 0 ;
    for(int i = 0 ; i < n ; i++)
    {
        if(a[i] == 0)
        {
            left = i ;
        }
        else
        {
            right = i ;
        }
    }
    cout << min(left,right) << endl;
    return  0;
}


//code in cpp
#include <bits/stdc++.h>
#define int long long
#define mod  1000000007
using namespace std;
signed main()
{
    int n ;
    cin >> n ;
    vector<int>a(n);
    for(int i = 0 ; i < n ; i++)
    {
        cin>>a[i];
    }
    int ans = 0;
    for(int i = n-1 ; i > 0 ; i--)
    {
        if (a[i] != a[n-1])
        {
            ans = i ;
            break;
        }
    }
    cout << ans + 1<< endl;
    return  0;
}


//code in cpp
#include <bits/stdc++.h>
#define int long long
#define mod  1000000007
using namespace std;
signed main()
{
    int n ;
    cin >> n ;
    vector<int>a(n);
    for(int i = 0 ; i < n ; i++)
    {
        cin>>a[i];
    }
    int ans ;
    for(int i = n-1 ; i > 0 ; i--)
    {
        if (a[i] != a[n-1])
        {
            ans = i ;
            break;
        }
    }
    cout << ans << endl;
    return  0;
}


#include<bits/stdc++.h>
using namespace std;
vector<int> v;
int main(){
	long long a,b,c,d,n,i,k,m,j;
	cin>>n;
	for(i=1; i<=n; i++){
		cin>>a;
		v.push_back(a);
	}
	for(i=v.size()-1; i>=1; i--){
		if(v[i]==v[i-1]) continue;
		else{
			cout<<i;
			exit(0);
		}
	}
	cout<<0;
}


#include<bits/stdc++.h>
using namespace std;
vector<int> v;
int main(){
	long long a,b,c,d,n,i,k,m,j;
	cin>>n;
	for(i=1; i<=n; i++){
		cin>>a;
		v.push_back(a);
	}
	reverse(v.begin(),v.end());
	for(i=v.size()-2; i>=0; i--){
		if(v[i]==v[i+1]) continue;
		else{
			cout<<i+1;
			exit(0);
		}
	}
	cout<<0;
}


#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 7;
int n;
int a[MAX_N];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    int left;
    int right;
    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i];
        if (a[i] == 0)
        {
            left = i;
        }
        else
        {
            right = i;
        }
    }
    int res = min(left, right);
    cout << res << "\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 7;
int n;
int a[MAX_N];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    vector<int> left;
    vector<int> right;
    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i];
        if (a[i] == 0)
        {
            left.push_back(i);
        }
        else
        {
            right.push_back(i);
        }
    }
    int res = min(left[left.size() - 1], right[right.size() - 1]);
    cout << res << "\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 7;
int n;
int a[MAX_N];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    int left = 0;
    int right = 0;
    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i];
        if (a[i] == 0)
        {
            left++;
        }
        else
        {
            right++;
        }
    }
    int res = 0;
    int index = 1;
    while (left > 0 && right > 0 && index <= n)
    {
        if (a[index] == 0)
        {
            left--;
        }
        else
        {
            right--;
        }
        res++;
        index++;
    }
    cout << res << "\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 7;
int n;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    int left;
    int right;
    for (int i = 1; i <= n; ++i)
    {
        int tmp;
        cin >> tmp;
        if (tmp == 0)
        {
            left = i;
        }
        else
        {
            right = i;
        }
    }
    int res = min(left, right);
    cout << res << "\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 7;
int n;
int a[MAX_N];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    vector<int> left;
    vector<int> right;
    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i];
        if (a[i] == 0)
        {
            left.push_back(i);
        }
        else
        {
            right.push_back(i);
        }
    }
    int res = min(left[left.size() - 1] - left[0], right[right.size() - 1] - right[0]);
    cout << res + 1 << "\n";
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main() {
int a,b=0,c,d=0,n,i;
int p[200005];
cin>>n;
for(i=1;i<=n;i++) {
    cin>>p[i];
    if(p[i]==0) {
        a=i;
        b++;
    }
    else {
        c=i;
        d++;
    }
}
//cout<<a<<b<<c<<d<<endl;
if(b>d) {
    cout<<c<<endl;
}
else {
    cout<<a<<endl;
}

}


#include<bits/stdc++.h>

using namespace std;

int main() {
int a,b=0,c,d=0,n,i;

cin>>n;
int p[n];
for(i=1;i<=n;i++) {
    cin>>p[i];
    if(p[i]==0) {
        a=i;

    }
    else {
        c=i;

    }
}
//cout<<a<<b<<c<<d<<endl;
if(a>c) {
    cout<<c<<endl;
}
else {
    cout<<a<<endl;
}

}


#include<bits/stdc++.h>

using namespace std;

int main() {
int a,b=0,c,d=0,n,i;

cin>>n;
int p[n];
for(i=1;i<=n;i++) {
    cin>>p[i];
    if(p[i]==0) {
        a=i+1;

    }
    else {
        c=i+1;

    }
}
//cout<<a<<b<<c<<d<<endl;
if(a>c) {
    cout<<c<<endl;
}
else {
    cout<<a<<endl;
}

}


#include<bits/stdc++.h>

using namespace std;

int main() {
int a,b=0,c,d=0,n,i;
int p[200001];
cin>>n;
for(i=1;i<=n;i++) {
    cin>>p[i];
    if(p[i]==0) {
        a=i;
        b++;
    }
    else {
        c=i;
        d++;
    }
}
//cout<<a<<b<<c<<d<<endl;
if(b>d) {
    cout<<c<<endl;
}
else {
    cout<<a<<endl;
}

}


#include<bits/stdc++.h>
using namespace std;

int main()
{
  int t,a,cnt=0;
  cin>>t;
  vector<int> v;
  for(int i=0;i<t;i++)
  {
    cin>>a;
    v.push_back(a);
    if(v[i]=1 && v[i-1]==0)
    {
      cnt++;
      break;
    }
    else
    {
      cnt++;
    }
  }
  cout<<cnt+1<<endl;

  return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
  int k;
  cin>>k;
  int i,cnt=0,cnt2=0;
  int x;

  for(int i=1;i<=k;i++)
  {
    cin>>x;
    if(x==1)
    {
      cnt=i;
    }
    else if(x==0)
    {
      cnt2=i;
    }
  }

  if(cnt<cnt2)
  {
    cout<<cnt<<endl;
  }
  else
  {
    cout<<cnt2<<endl;
  }

  return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
  int t,a,cnt=0;
  cin>>t;
  set<int> v;
  for(int i=0;i<t;i++)
  {
    cin>>a;
    v.insert(a);
  }
  cout<<v.size()+1<<endl;

  return 0;
}


#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>

using namespace std;

int i,j;

int main()
{
    long int n,pos,l;
    cin>>n;
    int a[n+1];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    l=a[n-1];
    if(n>2)
    {for(i=n-2;i>-1;i--)
        {

            if(a[i]!=l)
            {
                pos=i+1;
                break;
            }
        }
     cout<<pos;
    }
    else
    {
        cout<<n-1;
    }

    return 0;
}


#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>

using namespace std;

int i,j;

int main()
{
    long int n,pos;
    cin>>n;
    int a[n+1];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(i=0;i<n;i++)
    {
        int flag=0;
        for(j=i+1;j<n;j++)
        {
            if(a[j]==a[i])
            {
                flag=1;
            }
        }
        if(flag==0)
        {
            pos=i+1;
            break;
        }
    }
    cout<<pos;
    return 0;
}


#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>

using namespace std;

int i,j;

int main()
{
    long int n,pos,l;
    cin>>n;
    int a[n+1];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    l=a[n-1];
    for(i=n-2;i>0;i--)
    {

        if(a[i]!=l)
        {
            pos=i+1;
            break;
        }
    }
    cout<<pos;
    return 0;
}


#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>

using namespace std;

int i,j;

int main()
{
    int n,pos;
    cin>>n;
    int a[n+1];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(i=0;i<n;i++)
    {
        int flag=0;
        for(j=i+1;j<n;j++)
        {
            if(a[j]==a[i])
            {
                flag=1;
            }
        }
        if(flag==0)
        {
            pos=i+1;
            break;
        }
    }
    cout<<pos;
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int x,i,j,n,c0=0,c1=0,x1,x2;
    cin>>x;
    int n;
    for(i=0;i<x;i++)
    {
        cin>>n;
        if(n==0){
            x1=i;
            c0++;
        }
        else{
            x2=i;
            c1++;
        }
    }
    if(c0>=c1)
        cout<<x2+1<<endl;
    else
        cout<<x1+1<<endl;
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int x,i,j,c0=0,c1=0,x1,x2;
    cin>>x;
    int n;
    for(i=0;i<x;i++)
    {
        cin>>n;
        if(n==0){
            x1=i;
            c0++;
        }
        else{
            x2=i;
            c1++;
        }
    }
    if(c0>=c1)
        cout<<x2+1<<endl;
    else
        cout<<x1+1<<endl;
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int x,i,j,c0=0,c1=0,x1,x2;
    cin>>x;
    int n;
    for(i=0;i<x;i++)
    {
        cin>>n;
        if(n==0){
            x1=i;
            c0++;
        }
        else{
            x2=i;
            c1++;
        }
    }
    if(c0>c1)
        cout<<x2+1<<endl;
    else if(c0<c1)
        cout<<x1+1<<endl;
    else
    {
        if(x1>x2)
            cout<<x2+1;
        else
            cout<<x1+1;
    }
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int x,i,j,n,c0=0,c1=0,x1,x2;
    cin>>x;
    int a[x];
    for(i=0;i<x;i++)
    {
        cin>>a[i];
        if(a[i]==0){
            x1=i;
            c0++;
        }
        else{
            x2=i;
            c1++;
        }
    }
    if(c0>c1)
        cout<<x2+1<<endl;
    else
        cout<<x1+1<<endl;
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int x,i,x1,x2;
    cin>>x;
    int n;
    for(i=1;i<=x;i++)
    {
        cin>>n;
        if(n==0)
            x1=i;
        else
            x2=i;
    }
    cout<<min(x1,x2);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
	ll n, i, m[1000], neg = 0, teg = 0, q = 0, p;
	cin>>n;
	for(i = 1; i <= n; i ++){
		cin>>m[i];
		if(m[i] == 1) neg ++;
		else teg ++;
	}
	if(teg > neg){
		for(i = 1; i <= n; i ++){
			if(m[i] == 1) p = i;
		}
		cout<<p;
		}
	else{
		for(i = 1; i <= n; i ++){
			if(m[i] == 0) p = i;
		}
		cout<<p;
	}
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
	ll n, i, m[1000], 1too = 0, 0too = 0, q = 0;
	cin>>n;
	for(i = 1; i <= n; i ++){
		cin>>m[i];
		if(m[i] == 1) 1too ++;
		else 0too ++;
	}
	if(0too > 1too){
		for(i = 1; i <= n; i ++){
			if(m[i] == 1) p = i;
		}
		cout<<++p;
		}
	else{
		for(i = 1; i <= n; i ++){
			if(m[i] == 0) p = i;
		}
		cout<<--p;
	}
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
	ll n, i, m[1000], neg = 0, teg = 0, q = 0, p;
	cin>>n;
	for(i = 1; i <= n; i ++){
		cin>>m[i];
		if(m[i] == 1) neg ++;
		else teg ++;
	}
	if(teg > neg){
		for(i = 1; i <= n; i ++){
			if(m[i] == 1) p = i;
		}
		cout<<++p;
		}
	else{
		for(i = 1; i <= n; i ++){
			if(m[i] == 0) p = i;
		}
		cout<<--p;
	}
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
	ll n, i, m[200005], neg = 0, teg = 0, q = 0, p;
	cin>>n;
	for(i = 1; i <= n; i ++){
		cin>>m[i];
		if(m[i] == 1) neg ++;
		else teg ++;
	}
	if(m[n] == 0){
		for(i = 1; i <= n; i ++){
			if(m[i] == 1) p = i;
		}
			cout<<p;
		}
	else{
		for(i = 1; i <= n; i ++){
			if(m[i] == 0) p = i;
		}
		cout<<p;
	}
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
	ll n, i, m[200005], neg = 0, teg = 0, q = 0, p;
	cin>>n;
	for(i = 1; i <= n; i ++){
		cin>>m[i];
		if(m[i] == 1) neg ++;
		else teg ++;
	}
	if(teg > neg){
		for(i = 1; i <= n; i ++){
			if(m[i] == 1) p = i;
		}
		cout<<p;
		}
	else{
		for(i = 1; i <= n; i ++){
			if(m[i] == 0) p = i;
		}
		cout<<p;
	}
}


#include <bits/stdc++.h>
using namespace std;

int main(){
	int n;
	vector<int>arr(n);

	int ind = n-1;
	while(arr[ind] == arr[n-1])ind--;

	cout<<ind+1;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
	int n;
	vector<int>arr(n);

	for(int i = 0; i < n; i++){
		cin >> arr[i];
	}

	int ind = n-1;
	while(arr[ind] == arr[n-1])ind--;

	cout<<ind+1;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
	int n; cin >> n;
	vector<int>arr(n);

	for(int i = 0; i < n; i++){
		cin >> arr[i];
	}

	int ind = n-1;
	while(arr[ind] == arr[n-1])ind--;

	cout<<ind+1;
}


#include<bits/stdc++.h>
using namespace std;
main()
{
    int n,a[200000],z=0,o=0,mi=0,mx=0,i;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(int i=1;i<=n;i++)
    {
        if(a[i]==0)
        {
            z++;
        }
    else
        o++;
    }
 if(z<o)
 {
     cout<<z+1;
 }
 else
    cout<<o+1;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
main()
{
    int n,a[200000],z=0,o=0,mi=0,mx=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(int i=1;i<=n;i++)
    {
        if(a[i]==0)
        {
            z++;
        }
        else
            o++;
    }
    if(z==o)
    {
        cout<<o+1;
    }
 else
        cout<<(z-o);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
main()
{
    int n,a[200000],z=0,o=0,r,p;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(int i=1;i<=n;i++)
    {
        if(a[i]==0)
        {
            r=i;
        }
    else
        p=i;
    }
 if(r<p)
 {
     cout<<r;
 }
 else
    cout<<p;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
main()
{
    int n,a[200000],z=0,o=0,mi=0,mx=0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(int i=1;i<=n;i++)
    {
        if(a[i]==0)
        {
            z++;
        }
        else
            o++;
    }
    cout<<z-o;
}


#include<map>
#include<iostream>
#include<set>
#include<string>
#include <vector>

using namespace std;

int main(){
	int n , k= 0,lev=0, prav= 0;
	cin >> n;
	vector<int> vec(n);
	for(int i = 0 ; i < n; ++i){
		cin >> vec[i];
		if(vec[i]== 1)
		prav++;
		else
		lev++;
	}
	for(int i = 0 ; i < n; ++i){
	if(vec[i]== 1)
	{
	prav--;
	k++;

	}
	else
	{
	lev--;
	k++
	}
	if(lev == 0 || prav ==0){
		break;
	}
	cout << k;
	}

}


#include<map>
#include<iostream>
#include<set>
#include<string>
#include <vector>

using namespace std;

int main(){
	int n , k= 0,lev=0, prav= 0;
	cin >> n;
	vector<int> vec(n);
	for(int i = 0 ; i < n; ++i){
		cin >> vec[i];
		if(vec[i]== 1)
		prav++;
		else
		lev++;
	}
	for(int i = 0 ; i < n; ++i){
	if(vec[i]== 1)
	{
	prav--;
	k++;

	}
	else
	{
	lev--;
	k++;
	}
	if(lev == 0 || prav ==0){
		break;
	}
	cout << k;
	}

}


#include<map>
#include<iostream>
#include<set>
#include<string>
#include <vector>

using namespace std;

int main(){
	int n , k= 0,lev=0, prav= 0;
	cin >> n;
	vector<int> vec(n);
	for(int i = 0 ; i < n; ++i){
		cin >> vec[i];
		if(vec[i]== 1)
		prav++;
		else
		lev++;
	}
	for(int i = 0 ; i < n; ++i){
	if(vec[i]== 1)
	{
	prav--;
	k++;

	}
	else
	{
	lev--;
	k++;
	}
	if(lev == 0 || prav ==0){
		break;
	}

	}
	cout << k;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long int n,i,right,left;
	long int a[n];
	cin>>n;
	for(i=0;i<n;i++)
	cin>>a[i];
	for(i=0;i<n;i++)
	{
		if(a[i]==1)
		left=i;
		else
		right=i;
    }
	if(left<right)
	cout<<left+1;
	else
	cout<<right+1;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long int n,i,right=0,left=0;
	long int a[n];
	cin>>n;
	for(i=0;i<n;i++)
	cin>>a[i];
	for(i=0;i<n;i++)
	{
		if(a[i]==1)
		left=i;
		else
		right=i;
    }
	if(left<right)
	cout<<left+1;
	else
	cout<<right+1;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long int n,i,right=0,left=0;
	cin>>n;
	long int a[n];
	for(i=0;i<n;i++)
	cin>>a[i];
	for(i=0;i<n;i++)
	{
		if(a[i]==1)
		left=i;
		else
		right=i;
    }
	if(left<right)
	cout<<left+1;
	else
	cout<<right+1;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,i,right=0,left=0;
	long long a[n];
	cin>>n;
	for(i=0;i<n;i++)
	cin>>a[i];
	for(i=0;i<n;i++)
	{
		if(a[i]==1)
		left=i;
		else
		right=i;
    }
    if(n==250)
    cout<<left<<" "<<right;
	if(left<right)
	cout<<left+1;
	else
	cout<<right+1;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long int n,i,right=0,left=0;
	long int a[n];
	cin>>n;
	for(i=0;i<n;i++)
	cin>>a[i];
	for(i=0;i<n;i++)
	{
		if(a[i]==1)
		left=i;
		else
		right=i;
    }
    if(n==250)
    cout<<left<<" "<<right;
	if(left<right)
	cout<<left+1;
	else
	cout<<right+1;
}


#include <iostream>
using namespace std;

int main(){
int n;
cin >> n;
int t[n+1];
for(int i = 1; i <= n; i++){
  cin >> t[i];
}

 int a,b;

for(int i =  1; i <= n; i++){
  if(t[i] == 0){
    a = i;
  }
  if(t[i] == 1){
    b = i;
  }
}

if(b > a) cout << a;
if(b < a) cout << b;
if(b == a) cout << a;

}


int main(){
int n;
cin >> n;
int t[n+1];
for(int i = 1; i <= n; i++){
  cin >> t[i];
}

 int a,b;

for(int i =  1; i <= n; i++){
  if(t[i] == 0){
    a = i;
  }
  if(t[i] == 1){
    b = i;
  }
}

if(b > a) cout << a;
if(b < a) cout << b;
if(b == a) cout << a;

}


#include <iostream>
using namespace std;

int main(){
int n;
cin >> n;
int t[n+1];
for(int i = 1; i <= n; i++){
  cin >> t[i];
}

 int a,b;

for(int i =  1; i <= n; i++){
  if(t[i] == 0){
    a = i;
  }
  if(t[i] == 1){
    b = i;
  }
}

if(b > a) cout << a;
if(b < a) cout << b;
if(b == a) cout << a;

	return 0;
}


#include <iostream>
using namespace std;

int main(){
int n;
cin >> n;
int t[n];
for(int i = 1; i < n; i++){
  cin >> t[i];
}

 int a,b;

for(int i =  1; i < n; i++){
  if(t[i] == 0){
    a = i;
  }
  if(t[i] == 1){
    b = i;
  }
}

if(b > a) cout << a;
if(b < a) cout << b;
if(b == a) cout << a;

	return 0;
}


#include <iostream>

using namespace std;

int main()
{
   int x ,zeroes=0 , ones=0 ;
   cout << "enter how many doors there is \n";
   cin >>x;
   if (x < 2)
        {cout << "wrong number must have at least 2 doors \n";
            return -1;}
   int lis [x];
   cout << "enter the doors \n";
   for (int i = 0 ; i<x ; i++)
   {
       cin >> lis [i];
       if (lis[i] == 0) zeroes++;
       if (lis[i] == 1) ones++;

   }
   if (x == 2)
       if (lis[0] == lis[1])
            cout << "2";
        else
            cout << "1";
   else if(zeroes < ones)
        for (int i=0 ; i <= x-1 ; i++)
            {
                if (lis[i] == 0)
                    zeroes--;
                if (zeroes == 0)
                    {
                        cout << i+1;
                        return -1;
                    }
            }
    else if (zeroes > ones)
         for (int i=0 ; i <= x-1 ; i++)
            {
                if (lis[i] == 1)
                    ones--;
                if (ones == 0)
                    {
                        cout << i+1;
                        return -1;
                    }
            }

    else if (ones == zeroes)
        {
            for (int k = 0 ; k <= x ; k++)
                {
                if (lis[k] == 0)
                    zeroes--;
                if (lis[k] == 1)
                    ones--;
                if (ones == 0){
                        cout << k+1;
                        return -1;}
                if (zeroes == 0){
                        cout << k+1;
                        return -1;}
        }}

}


#include <iostream>

using namespace std;

int main()
{
   int x ,zeroes=0 , ones=0 ;
   cout << "enter how many doors there is \n";
   cin >>x;
   if (x < 2)
        {cout << "wrong number must have at least 2 doors \n";
            return -1;}
   int lis [x];
   //cout << "enter the doors \n";
   for (int i = 0 ; i<x ; i++)
   {
       cin >> lis [i];
       if (lis[i] == 0) zeroes++;
       if (lis[i] == 1) ones++;

   }
   if (x == 2)
       if (lis[0] == lis[1])
            cout << "2";
        else
            cout << "1";
   else if(zeroes < ones)
        for (int i=0 ; i <= x-1 ; i++)
            {
                if (lis[i] == 0)
                    zeroes--;
                if (zeroes == 0)
                    {
                        cout << i+1;
                        return 0;
                    }
            }
    else if (zeroes > ones)
         for (int i=0 ; i <= x-1 ; i++)
            {
                if (lis[i] == 1)
                    ones--;
                if (ones == 0)
                    {
                        cout << i+1;
                        return 0;
                    }
            }

    else if (ones == zeroes)
        {
            for (int k = 0 ; k <= x ; k++)
                {
                if (lis[k] == 0)
                    zeroes--;
                if (lis[k] == 1)
                    ones--;
                if (ones == 0){
                        cout << k+1;
                        return 0;}
                if (zeroes == 0){
                        cout << k+1;
                        return 0;}
        }}

}


#include <iostream>

using namespace std;

double main()
{
   double x ,zeroes=0 , ones=0 ;
  // cout << "enter how many doors there is \n";
   cin >>x;
   if (x < 2)
        {cout << "wrong number must have at least 2 doors \n";
            return -1;}
   double lis [x];
   //cout << "enter the doors \n";
   for (double i = 0 ; i<x ; i++)
   {
       cin >> lis [i];
       if (lis[i] == 0) zeroes++;
       if (lis[i] == 1) ones++;

   }
   if (x == 2)
       if (lis[0] == lis[1])
            cout << "2";
        else
            cout << "1";
   else if(zeroes < ones)
        for (double i=0 ; i <= x-1 ; i++)
            {
                if (lis[i] == 0)
                    zeroes--;
                if (zeroes == 0)
                    {
                        cout << i+1;
                        return 0;
                    }
            }
    else if (zeroes > ones)
         for (double i=0 ; i <= x-1 ; i++)
            {
                if (lis[i] == 1)
                    ones--;
                if (ones == 0)
                    {
                        cout << i+1;
                        return 0;
                    }
            }

    else if (ones == zeroes)
        {
            for (double k = 0 ; k <= x ; k++)
                {
                if (lis[k] == 0)
                    zeroes--;
                if (lis[k] == 1)
                    ones--;
                if (ones == 0){
                        cout << k+1;
                        return 0;}
                if (zeroes == 0){
                        cout << k+1;
                        return 0;}
        }}

}


#include <iostream>

using namespace std;

int main()
{
   int x ;
   double zeroes=0 , ones=0 ;
   //cout << "enter how many doors there is \n";
   cin >>x;
   if (x < 2)
        {cout << "wrong number must have at least 2 doors \n";
            return -1;}
   int lis [x];
   //cout << "enter the doors \n";
   for (int i = 0 ; i<x ; i++)
   {
       cin >> lis [i];
       if (lis[i] == 0) zeroes++;
       if (lis[i] == 1) ones++;

   }
   if (x == 2)
       if (lis[0] == lis[1])
            cout << "2";
        else
            cout << "1";
   else if(zeroes < ones)
        for (int i=0 ; i <= x-1 ; i++)
            {
                if (lis[i] == 0)
                    zeroes--;
                if (zeroes == 0)
                    {
                        cout << i+1;
                        return 0;
                    }
            }
    else if (zeroes > ones)
         for (int i=0 ; i <= x-1 ; i++)
            {
                if (lis[i] == 1)
                    ones--;
                if (ones == 0)
                    {
                        cout << i+1;
                        return 0;
                    }
            }

    else if (ones == zeroes)
        {
            for (int k = 0 ; k <= x ; k++)
                {
                if (lis[k] == 0)
                    zeroes--;
                if (lis[k] == 1)
                    ones--;
                if (ones == 0){
                        cout << k+1;
                        return 0;}
                if (zeroes == 0){
                        cout << k+1;
                        return 0;}
        }}

}


#include <iostream>

using namespace std;

int main()
{
   double x ,zeroes=0 , ones=0 ;
  // cout << "enter how many doors there is \n";
   cin >>x;
   if (x < 2)
        {cout << "wrong number must have at least 2 doors \n";
            return -1;}
   double lis [x];
   //cout << "enter the doors \n";
   for (double i = 0 ; i<x ; i++)
   {
       cin >> lis [i];
       if (lis[i] == 0) zeroes++;
       if (lis[i] == 1) ones++;

   }
   if (x == 2)
       if (lis[0] == lis[1])
            cout << "2";
        else
            cout << "1";
   else if(zeroes < ones)
        for (double i=0 ; i <= x-1 ; i++)
            {
                if (lis[i] == 0)
                    zeroes--;
                if (zeroes == 0)
                    {
                        cout << i+1;
                        return 0;
                    }
            }
    else if (zeroes > ones)
         for (double i=0 ; i <= x-1 ; i++)
            {
                if (lis[i] == 1)
                    ones--;
                if (ones == 0)
                    {
                        cout << i+1;
                        return 0;
                    }
            }

    else if (ones == zeroes)
        {
            for (double k = 0 ; k <= x ; k++)
                {
                if (lis[k] == 0)
                    zeroes--;
                if (lis[k] == 1)
                    ones--;
                if (ones == 0){
                        cout << k+1;
                        return 0;}
                if (zeroes == 0){
                        cout << k+1;
                        return 0;}
        }}

}


#include <iostream>

using namespace std;

int main()
{
   int x ,zeroes=0 , ones=0 ;
  // cout << "enter how many doors there is \n";
   cin >>x;
   if (x < 2)
        {cout << "wrong number must have at least 2 doors \n";
            return -1;}
   int lis [x];
   //cout << "enter the doors \n";
   for (int i = 0 ; i<x ; i++)
   {
       cin >> lis [i];
       if (lis[i] == 0) zeroes++;
       if (lis[i] == 1) ones++;

   }
   if (x == 2)
       if (lis[0] == lis[1])
            cout << "2";
        else
            cout << "1";
   else if(zeroes < ones)
        for (int i=0 ; i <= x-1 ; i++)
            {
                if (lis[i] == 0)
                    zeroes--;
                if (zeroes == 0)
                    {
                        cout << i+1;
                        return 0;
                    }
            }
    else if (zeroes > ones)
         for (int i=0 ; i <= x-1 ; i++)
            {
                if (lis[i] == 1)
                    ones--;
                if (ones == 0)
                    {
                        cout << i+1;
                        return 0;
                    }
            }

    else if (ones == zeroes)
        {
            for (int k = 0 ; k <= x ; k++)
                {
                if (lis[k] == 0)
                    zeroes--;
                if (lis[k] == 1)
                    ones--;
                if (ones == 0){
                        cout << k+1;
                        return 0;}
                if (zeroes == 0){
                        cout << k+1;
                        return 0;}
        }}

}


#include <iostream>

using namespace std;

int main()
{
   double x ,zeroes=0 , ones=0 ;
  // cout << "enter how many doors there is \n";
   cin >>x;
   if (x < 2)
        {cout << "wrong number must have at least 2 doors \n";
            return -1;}
   double lis [x];
   //cout << "enter the doors \n";
   for (double i = 0 ; i<x ; i++)
   {
       cin >> lis [i];
       if (lis[i] == 0) zeroes++;
       if (lis[i] == 1) ones++;

   }
   if (x == 2)
       if (lis[0] == lis[1])
            cout << "2";
        else
            cout << "1";
   else if(zeroes < ones)
        for (double i=0 ; i <= x-1 ; i++)
            {
                if (lis[i] == 0)
                    zeroes--;
                if (zeroes == 0)
                    {
                        cout << i+1;
                        return 0;
                    }
            }
    else if (zeroes > ones)
         for (double i=0 ; i <= x-1 ; i++)
            {
                if (lis[i] == 1)
                    ones--;
                if (ones == 0)
                    {
                        cout << i+1;
                        return 0;
                    }
            }

    else if (ones == zeroes)
        {
            for (double k = 0 ; k <= x ; k++)
                {
                if (lis[k] == 0)
                    zeroes--;
                if (lis[k] == 1)
                    ones--;
                if (ones == 0){
                        cout << k+1;
                        return 0;}
                if (zeroes == 0){
                        cout << k+1;
                        return 0;}
        }}
        return 0;

}


#include <iostream>

using namespace std;

int main()
{
   int x ;
   int  zeroes=0 , ones=0 ,i;
   //cout << "enter how many doors there is \n";
   cin >>x;
   if (x < 2)
        {cout << "wrong number must have at least 2 doors \n";
            return 0;}
   int lis [x];
   //cout << "enter the doors \n";
   for ( i = 0 ; i<x ; i++)
   {
       cin >> lis [i];
       if (lis[i] == 0) zeroes=i+1;
       if (lis[i] == 1) ones=i+1;

   }
   if (x == 2)
       {if (lis[0] == lis[1])
            {cout << "2";
            return 0;}
        else
            {cout << "1";
            return 0;}
       }
    if(lis[x-1] == 0)
                cout<< ones;

    if(lis[x-1] == 1)
                cout<<zeroes;
}


#include <iostream>

using namespace std;

int main()
{
   int x ,zeroes=0 , ones=0 ;
   cout << "enter how many doors there is \n";
   cin >>x;
   if (x < 2)
        {cout << "wrong number must have at least 2 doors \n";
            return -1;}
   int lis [x];
   cout << "enter the doors \n";
   for (int i = 0 ; i<x-1 ; i++)
   {
       cin >> lis [i];
       if (lis[i] == 0) zeroes++;
       if (lis[i] == 1) ones++;

   }
   if (x == 2)
       if (lis[0] == lis[1])
            cout << "2";
        else
            cout << "1";
   else if(zeroes < ones)
        for (int i=0 ; i <= x-1 ; i++)
            {
                if (lis[i] == 0)
                    zeroes--;
                if (zeroes == 0)
                    {
                        cout << i+1;
                        return -1;
                    }
            }
    else if (zeroes > ones)
         for (int i=0 ; i <= x-1 ; i++)
            {
                if (lis[i] == 1)
                    ones--;
                if (ones == 0)
                    {
                        cout << i+1;
                        return -1;
                    }
            }

    else if (ones == zeroes)
        {
            for (int k = 0 ; k <= x ; k++)
                {
                if (lis[k] == 0)
                    zeroes--;
                if (lis[k] == 1)
                    ones--;
                if (ones == 0){
                        cout << k+1;
                        return -1;}
                if (zeroes == 0){
                        cout << k+1;
                        return -1;}
        }}

}


#include <iostream>

using namespace std;

int main()
{
   int x ,zeroes=0 , ones=0 ;
   //cout << "enter how many doors there is \n";
   cin >>x;
   if (x < 2)
        {cout << "wrong number must have at least 2 doors \n";
            return -1;}
   int lis [x];
   //cout << "enter the doors \n";
   for (int i = 0 ; i<x ; i++)
   {
       cin >> lis [i];
       if (lis[i] == 0) zeroes++;
       if (lis[i] == 1) ones++;

   }
   if (x == 2)
       if (lis[0] == lis[1])
            cout << "2";
        else
            cout << "1";
   else if(zeroes < ones)
        for (int i=0 ; i <= x-1 ; i++)
            {
                if (lis[i] == 0)
                    zeroes--;
                if (zeroes == 0)
                    {
                        cout << i+1;
                        return 0;
                    }
            }
    else if (zeroes > ones)
         for (int i=0 ; i <= x-1 ; i++)
            {
                if (lis[i] == 1)
                    ones--;
                if (ones == 0)
                    {
                        cout << i+1;
                        return 0;
                    }
            }

    else if (ones == zeroes)
        {
            for (int k = 0 ; k <= x ; k++)
                {
                if (lis[k] == 0)
                    zeroes--;
                if (lis[k] == 1)
                    ones--;
                if (ones == 0){
                        cout << k+1;
                        return 0;}
                if (zeroes == 0){
                        cout << k+1;
                        return 0;}
        }}

}


#include <iostream>

using namespace std;

int main()
{
   int x ;
   int  zeroes=0 , ones=0 ,i;
   cout << "enter how many doors there is \n";
   cin >>x;
   if (x < 2)
        {cout << "wrong number must have at least 2 doors \n";
            return 0;}
   int lis [x];
   cout << "enter the doors \n";
   for ( i = 0 ; i<x ; i++)
   {
       cin >> lis [i];
       if (lis[i] == 0) zeroes=i+1;
       if (lis[i] == 1) ones=i+1;

   }
   if (x == 2)
       {if (lis[0] == lis[1])
            {cout << "2";
            return 0;}
        else
            {cout << "1";
            return 0;}
       }
    if(lis[x-1] == 0)
                cout<< ones;

    if(lis[x-1] == 1)
                cout<<zeroes;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n,count1=1,count2=0;cin>>n;int a[n];
    if(n%2!=0)
        n-=1;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]==0)
            {count1++;if(count1>=(n/2)){cout<<count1+count2;break;}}
        else
            {count2++;if(count2>=(n/2)){cout<<count1+count2;break;}}
    }
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n,count1=1,count2=0;cin>>n;int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]==0)
            {count1++;if(count1>(n/2)){cout<<count1+count2;break;}}
        else
            {count2++;if(count2>(n/2)){cout<<count1+count2;break;}}
    }
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n,count1=1,count2=0;cin>>n;int a[n];
    if(n%2!=0)
        n+=1;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]==0)
            {count1++;if(count1>=(n/2)){cout<<count1+count2;break;}}
        else
            {count2++;if(count2>=(n/2)){cout<<count1+count2;break;}}
    }
}


#include<bits/stdc++.h>

using namespace std;
typedef long long int ll;
int main()
{
    ll n,flag=0;cin>>n;ll a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    if(a[n-1]==1)
        flag=1;
    for(int i=n-2;i>=0;i++)
    {
        if(flag==1)
        {
            if(a[i]==0)
                cout<<i+1;
        }
        else
            if(a[i]==1)
                cout<<i+1;
    }

}


#include<bits/stdc++.h>

using namespace std;
typedef long long int ll;
int main()
{
    ll n,flag=0;cin>>n;ll a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    if(a[n-1]==1)
        flag=1;
    for(int i=n-2;i>=0;i--)
    {
        if(flag==1)
        {
            if(a[i]==0)
                cout<<i+1;
        }
        else
            if(a[i]==1)
                cout<<i+1;
    }

}


#include<bits/stdc++.h>

using namespace std;
typedef long long int ll;
int main()
{
    ll n,i,count=0;cin>>n;int a[n];
    if(n%2!=0)
        n+=1;
    for(i=0;i<n;i++)
        cin>>a[i];
        sort(a,a+n);
    while(a[i]!=0)
    {count++;i++;}
    if(count<=(n/2))
        cout<<count;
    else
        cout<<n-count;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n,count1=1,count2=0;cin>>n;int a[n];
    if(n%2!=0)
        n-=1;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]==0)
            {count1++;if(count1>(n/2)){cout<<count1+count2;break;}}
        else
            {count2++;if(count2>(n/2)){cout<<count1+count2;break;}}
    }
}


#include<bits/stdc++.h>

using namespace std;
typedef long long int ll;
int main()
{
    ll n,flag=0;cin>>n;ll a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    if(a[n-1]==1)
        flag=1;
    for(int i=n-2;i>=0;i--)
    {
        if(flag==1)
        {
            if(a[i]==0)
                {cout<<i+1;break;}
        }
        else
            if(a[i]==1)
                {cout<<i+1;break;}
    }

}


#include <bits/stdc++.h>
  using namespace std;
     int main(){
   int n;
   cin>>n;
  int l=-1,r=-1;
     for(int i=1;i<=n;i++){
           int a;
             cin>> a;
               if(a==1){
                     l=i;
               }
                else{
                    r=i;
                }
     }
    cout<<min(l,r)<<endl;
        return 0;
     }


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int a;
	cin>>a;
	vector<int> v;
	int k[2]={0};
	while(a--)
	{
		int b;
		cin>>b;
		v.pb(b);
		k[b]++;
	}
	int res=0;
	for(auto i:v)
	{

		//cout<<k[i]<<endl;
		k[i]--;
		res++;
		if(k[i]==0){

			break;
		}
	}
	cout<<res;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){

  int a;
  cin >> a;
  int left=0,right=0;
  vector<int> nums;
  for(int i=0;i<a;i++){
    int b;
    cin >> b;
    if(b==0)left++;
    if(b==1)right++;
    nums.push_back(b);
  }
  int r=0;
  for(int i:nums){
    if(i==0){left--;r++;}
    if(i==1){right--;r++;}
    if(left==0||right==0){cout<<r;return 0;}
  }
}


#include <bits/stdc++.h>
using namespace std;
//void sort3(int &a, int &b, int &c) {
//    if (a > b) std::swap(a, b);
//    if (b > c) std::swap(b, c);
//    if (a > b) std::swap(a, b);
//}

int main() {
    int n;
    cin >> n;
    int l = 0, r = 0;
    int x;
    for (int i = 0; i < n; i++) {
        cin >> x;
        if (x == 0) l = i;
        else r = i;
    }

    cout << min(l, r);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
//void sort3(int &a, int &b, int &c) {
//    if (a > b) std::swap(a, b);
//    if (b > c) std::swap(b, c);
//    if (a > b) std::swap(a, b);
//}

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

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
//void sort3(int &a, int &b, int &c) {
//    if (a > b) std::swap(a, b);
//    if (b > c) std::swap(b, c);
//    if (a > b) std::swap(a, b);
//}

int main() {
    int n;
    cin >> n;
    int l = 0, r = 0;
    int x;
    for (int i = 0; i < n; i++) {
        cin >> x;
        if (x == 0) l = i + 1;
        else r = i + 1;
    }

    cout << min(l, r);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
//void sort3(int &a, int &b, int &c) {
//    if (a > b) std::swap(a, b);
//    if (b > c) std::swap(b, c);
//    if (a > b) std::swap(a, b);
//}

int main() {
    int n;
    cin >> n;
    int l = 0, r = 0;
    int x
    for (int i = 0; i < n; i++) {
        cin >> x;
        if (x == 0) l = i;
        else r = i;
    }

    cout << min(l, r);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const ll N = 1e5 + 5, MOD = 1e9+7;

ll n,ans;
ll maxx1,maxx2;
ll a[N];
vector <ll> v;

ll power( ll x, ll y ){
    ll res=1;

    while( y>0 ){
        if(y&1)
            res*=x;

        y=y>>1;
        x=x*x;
    }
    return res;
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin>>n;
    for( ll i=0; i<n; i++ )     cin>>a[i];

    for( ll i=(n-1); i>=0; i-- ){
        if(a[i]==1){
            maxx1=i;
            break;
        }
    }

    for( ll i=(n-1); i>=0; i-- ){
        if(a[i]==0){
            maxx2=i;
            break;
        }
    }
    ans=min(maxx1,maxx2)+1;
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const ll N = 2e5 + 5, MOD = 1e9+7;

ll n,ans;
ll maxx1=MOD,maxx2=MOD;
ll a[N];

ll power( ll x, ll y ){
    ll res=1;

    while( y>0 ){
        if(y&1)
            res*=x;

        y=y>>1;
        x=x*x;
    }
    return res;
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin>>n;
    for( ll i=1; i<=n; i++ )     cin>>a[i];

    ans=a[n];

    for( ll i=n; i>=1; i-- ){
       if(a[i]!=ans){
           cout<<i<<endl;
           return 0;
       }
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const ll N = 1e5 + 5, MOD = 1e9+7;

ll n,ans;
ll maxx1=MOD,maxx2=MOD;
ll a[N];

ll power( ll x, ll y ){
    ll res=1;

    while( y>0 ){
        if(y&1)
            res*=x;

        y=y>>1;
        x=x*x;
    }
    return res;
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin>>n;
    for( ll i=1; i<=n; i++ )     cin>>a[i];

    ans=a[n];

    for( ll i=n; i>=1; i-- ){
       if(a[i]!=ans){
           cout<<i<<endl;
           return 0;
       }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const ll N = 1e5 + 5, MOD = 1e9+7;

ll n,ans;
ll maxx1=MOD,maxx2=MOD;
ll a[N];

ll power( ll x, ll y ){
    ll res=1;

    while( y>0 ){
        if(y&1)
            res*=x;

        y=y>>1;
        x=x*x;
    }
    return res;
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin>>n;
    for( ll i=1; i<=n; i++ )     cin>>a[i];

    ans=a[n];

    for( ll i=n; i>=1; i-- ){
       if(a[i]!=ans){
           cout<<a[i]<<endl;
           return 0;
       }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const ll N = 1e5 + 5, MOD = 1e9+7;

ll n,ans;
ll maxx1=MOD,maxx2=MOD;
ll a[N];
vector <ll> v;

ll power( ll x, ll y ){
    ll res=1;

    while( y>0 ){
        if(y&1)
            res*=x;

        y=y>>1;
        x=x*x;
    }
    return res;
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin>>n;
    for( ll i=0; i<n; i++ )     cin>>a[i];

    for( ll i=(n-1); i>=0; i-- ){
        if(a[i]==1){
            maxx1=i;
            break;
        }
    }

    for( ll i=(n-1); i>=0; i-- ){
        if(a[i]==0){
            maxx2=i;
            break;
        }
    }
    ans=min(maxx1,maxx2)+1;
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const ll N = 1e5 + 5, MOD = 1e9+7;

ll n,ans;
ll maxx1=MOD,maxx2=MOD;
ll a[N];

ll power( ll x, ll y ){
    ll res=1;

    while( y>0 ){
        if(y&1)
            res*=x;

        y=y>>1;
        x=x*x;
    }
    return res;
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin>>n;
    for( ll i=1; i<=n; i++ )     cin>>a[i];

    ans=a[n];

    for( ll i=n; i>=1; i-- ){
       if(a[i]!=ans){
           cout<<i<<endl;
           return 0;
       }
    }
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const ll N = 2e5 + 5, MOD = 1e9+7;

ll n,ans;
ll maxx1=MOD,maxx2=MOD;
ll a[N];
vector <ll> v;

ll power( ll x, ll y ){
    ll res=1;

    while( y>0 ){
        if(y&1)
            res*=x;

        y=y>>1;
        x=x*x;
    }
    return res;
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin>>n;
    for( ll i=0; i<n; i++ )     cin>>a[i];

    for( ll i=(n-1); i>=0; i-- ){
        if(a[i]==1){
            maxx1=i;
            break;
        }
    }

    for( ll i=(n-1); i>=0; i-- ){
        if(a[i]==0){
            maxx2=i;
            break;
        }
    }
    ans=min(maxx1,maxx2)+1;
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define loop(n)  for(int i=0;i<n;i++)
using namespace std;
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin>>n;
  int lr[2];
  loop(n)
  {
    int t;
    cin>>t;
    lr[t]=i+1;
  }
  cout<<min(lr[0],lr[1]);
  return  0;
}


#include<bits/stdc++.h>
#define loop(n)  for(int i=0;i<n;i++)
using namespace std;
int main()
{
  int n;
  cin>>n;
  int lr[2];
  loop(n)
  {
    int t;
    cin>>t;
    lr[t]=i;
  }
  cout<<min(lr[0],lr[1]) + 1;
  return  0;
}


#include<bits/stdc++.h>
#define loop(n)  for(int i=0;i<n;i++)
using namespace std;
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin>>n;
  int lr[2];
  loop(n)
  {
    int t;
    cin>>t;
    lr[t]=i;
  }
  cout<<min(lr[0],lr[1]) + 1;
  return  0;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>

#define FILE
//#define DEBUG
#ifdef DEBUG
#define TIMER
#define INFO
#endif

#ifdef FILE
#define OUT fout
#define IN fin
#else
#define OUT cout
#define IN cin
#endif

#ifdef TIMER
#include "SimpleTimer.h"
	SimpleTimer simple_timer;
#endif

#define all(a) begin(a), end(a)

using namespace std;

typedef unsigned long long ull;
typedef unsigned long ul;
typedef unsigned int ui;
typedef long long ll;
typedef pair<long, long> pll;
typedef pair<ul, ul> pulul;

int main()
{
#ifdef FILE
	fstream fin, fout;
	fin.open("input.txt", fstream::in);
	fout.open("output.txt", fstream::out);
#else
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#endif

	long a, k;
	short last, temp;

	IN >> a >> last;

	for (long i = 1; i < a; i++)
	{
		IN >> temp;
		if (temp != last)
		{
			k = i;
			break;
		}
	}

	OUT << a - k << endl;

#ifdef FILE
	fin.close();
	fout.close();
#endif

	return 0;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>

#define FILE
//#define DEBUG
#ifdef DEBUG
#define TIMER
#define INFO
#endif

#ifdef FILE
#define OUT fout
#define IN fin
#else
#define OUT cout
#define IN cin
#endif

#ifdef TIMER
#include "SimpleTimer.h"
	SimpleTimer simple_timer;
#endif

#define all(a) begin(a), end(a)

using namespace std;

typedef unsigned long long ull;
typedef unsigned long ul;
typedef unsigned int ui;
typedef long long ll;
typedef pair<long, long> pll;
typedef pair<ul, ul> pulul;

int main()
{
#ifdef FILE
	fstream fin, fout;
	fin.open("input.txt", fstream::in);
	fout.open("output.txt", fstream::out);
#else
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#endif

	long a, k;
	short first;
	vector<short> doors;

	IN >> a;
	doors.resize(a);

	for (long i = 0; i < a; i++)
		IN >> doors[i];

	first = doors[a - 1];
	for (long i = a - 1; i >= 0; i--)
		if (doors[i] != first)
		{
			k = i + 1;
			break;
		}

	OUT << k;

#ifdef FILE
	fin.close();
	fout.close();
#endif

	return 0;
}


from math import *
from copy import *
from string import *				# alpha = ascii_lowercase
from random import *
from sys import stdin
from sys import maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *
from collections import Counter		# d = dict(Counter(l))
import math

def bin1(l,r,k,t,b,val,ans):
	if(l>r):
		return ans
	else:
		mid=(l+r)//2
		v=k**mid
		if(v==val):
			return v
		elif(v>val):
			ans=mid
			return bin1(mid+1,r,k,t,b,val,ans)
		else:
			return bin1(l,mid-1,k,t,b,val,ans)

def bin2(l,r,k,t,b,val,ans):
	if(l>r):
		return ans
	else:
		mid=(l+r)//2
		v=t*(k**mid)+b*(mid)
		if(v==val):
			return v
		elif(v>val):
			ans=mid
			return bin2(l,mid-1,k,t,b,val,ans)
		else:
			return bin2(mid+1,r,k,t,b,val,ans)

def SieveOfEratosthenes(n):

    # Create a boolean array "prime[0..n]" and initialize
    #  all entries it as true. A value in prime[i] will
    # finally be false if i is Not a prime, else true.
    prime = [True for i in range(n+1)]
    p = 2
    while (p * p <= n):

        # If prime[p] is not changed, then it is a prime
        if (prime[p] == True):

            # Update all multiples of p
            for i in range(p * p, n+1, p):
                prime[i] = False
        p += 1
    l=[]
    for i in range(2,n+1):
    	if(prime[i]):
    		l.append(i)
    return l
def bin(l,r,ll,val):
	if(l>r):
		return -1
	else:
		mid=(l+r)//2
		if(val>=ll[mid][0] and val<=ll[mid][1]):
			return mid
		elif(val<ll[mid][0]):
			return bin(l,mid-1,ll,val)
		else:
			return bin(mid+1,r,ll,val)
def deci(n):
	s=""
	while(n!=0):
		if(n%2==0):
			n=n//2
			s="0"+s
		else:
			n=n//2
			s="1"+s
	return s
def diff(s1,s2):
	if(len(s1)<len(s2)):
		v=len(s1)
		while(v!=len(s2)):
			s1="0"+s1
			v=v+1
	else:
		v=len(s2)
		while(v!=len(s1)):
			s2="0"+s2
			v=v+1
	c=0
	for i in range(len(s1)):
		if(s1[i:i+1]!=s2[i:i+1]):
			c=c+1
	return c
from sys import stdin, stdout
def fac(a,b):
	v=a
	while(a!=b):
		v*=a-1
		a=a-1
	return v
def bino(l,r,n):
	if(l>r):
		return -1
	else:
		mid=(l+r)//2
		val1=math.log((n/mid)+1,2)
		val2=int(val1)
		if(val1==val2):
			return val1
		elif(val1<1.0):
			return bino(l,mid-1,n)
		else:
			return bino(mid+1,r,n)

def binary(l,r,ll,val,ans):
	if(l>r):
		return ans
	else:
		mid=(l+r)//2
		if(ll[mid]==val):
			return ll[mid]
		elif(ll[mid]<val):
			ans=ll[mid]
			return binary(mid+1,r,ll,val,ans)
		else:
			return binary(l,mid-1,ll,val,ans)
def check(n):
	v=1
	while(n!=0):
		if(n%10==0 or n%10==1):
			n=n//10
		else:
			v=0
			break
	return v

if __name__ == '__main__':
	n,m=map(int,stdin.readline().split(" "))
	s=set()
	for i in range(n):
		l=list(map(int,stdin.readline().split(" ")))
		for j in range(1,len(l)):
			s.add(l[j])
	if(len(s)==m):
		stdout.write(str("YES")+"\n")
	else:
		stdout.write(str("NO")+"\n")


a, b = [int(x) for x in input().split()]
bulb = set()
for i in range(a):
    e = input().split()
    bulb.update(set(e[1:]))
print(['NO','YES'][len(bulb) == b])


n=list(map(int,input().split()))
li=[]
for i in range(n[0]):
    k=list(map(int,input().split()))
    for j in k:
        if j not in li:
            li.append(j)
if len(li)==n[1]:
    print('YES')
else:
    print('NO')


n=list(map(int,input().split()))
li=[]
for i in range(n[0]):
    k=list(map(int,input().split()))
    for j in range(1,len(k)):
        if k[j] not in li:
            li.append(k[j])
if len(li)==n[1]:
    print('YES')
else:
    print('NO')


n=list(map(int,input().split()))
li=[]
for i in range(n[0]):
    k=list(map(int,input().split()))
    for j in range(1,len(k)):
        if k[j] not in li:
            li.append(j)
if len(li)==n[1]:
    print('YES')
else:
    print('NO')


# -*- coding: utf-8 -*-
"""
Created on Tue Nov  3 21:38:06 2020

@author: jion
"""

n,m = map(int,input().split())
L = []
no = True
for i in range(n):
    L += input().split()
    if len(set(L)) == 4:
        no = False
        break
print(['YES','NO'][no])


# -*- coding: utf-8 -*-
"""
Created on Tue Nov  3 21:38:06 2020

@author: jion
"""

n,m = map(int,input().split())
L = []
no = True
for i in range(n):
    L += (input().split())[1:]
    if len(set(L)) == m:
        no = False
        break
print(['YES','NO'][no])


# -*- coding: utf-8 -*-
"""
Created on Tue Nov  3 21:38:06 2020

@author: jion
"""

n,m = map(int,input().split())
L = []
no = True
for i in range(n):
    L += input().split()
    if len(set(L)) == m:
        no = False
        break
print(['YES','NO'][no])


n, m = map(int, input().split())
sett = set()
for i in range(n):
    x = list(map(int, input().split()))
    for j in range(1, len(x)):
        sett.add(x[j])
if len(sett) == m:
    print('YES')
else:
    print('NO')


import math

nm = input().split()
n = int(nm[0])
m = int(nm[1])

lis = [ 0 for i in range(m+1)]
for _ in range(n) :
    inp =  map(int, input().split())
    for i in inp:
        lis[i]=1
if sum(lis)==m:
    print("YES")
else:
    print("NO")


nm = input().split())
n = int(nm[0])
m = int(nm[1])

lis = [0 for i in range(m+1)]
for _ in n :
    inp =  map(int, input().split())
    for i in inp:
        lis[i]=1
if sum(lis)==m:
    print("YES")
else:
    print("NO")


nm = input().split()
n = int(nm[0])
m = int(nm[1])

lis = [ 0 for i in range(m+1)]
for _ in n :
    inp =  map(int, input().split())
    for i in inp:
        lis[i]=1
if sum(lis)==m:
    print("YES")
else:
    print("NO")


import math

nm = input().split()
n = int(nm[0])
m = int(nm[1])

lis = [ 0 for i in range(m+1)]
for _ in range(n) :
    inp =  list(map(int, input().split()))

    inp.pop(0)
    for i in inp:
        lis[i]=1
        prev = i
if sum(lis)==m:
    print("YES")
else:
    print("NO")


x,y=map(int,input().split())
b=[]
z=[i for i in range(1,y+1)]
for i in range(x):
	a=(list(map(int,input().split())))
	del a[0]
	b=list(set(b+a))
	b.sort()
if z==b:
	print("YES")
else:
	print("NO")


n,m=map(int,input().split())
s=set()
for t in range(n):
    l=set(map(int,input().split()))
    s=s|l
if len(s)==m:
    print('YES')
else:
    print('NO')


n,m=map(int,input().split())
s=set()
for t in range(n):
    l=list(map(int,input().split()))
    l=set(l[1:])
    s=s|l
if len(s)==m:
    print('YES')
else:
    print('NO')


# -*- coding: utf-8 -*-
"""
Created on Sun Nov  8 10:05:21 2020

@author: HUAWEI Mate 40 Pro
"""

m, n = map(int,input().split())
l = [False for i in range(0,n)]

for i in range(0,m):
    for j in [int(x) for x in input().split()][1:]:
        if not l[j-1]:
            l[j-1] = True
print(["NO","YES"][min(l)])


# -*- coding: utf-8 -*-
"""
Created on Sun Nov  8 10:05:21 2020

@author: HUAWEI Mate 40 Pro
"""

m, n = map(int,input().split())
l = [False for i in range(0,n)]

for i in range(0,m):
    for j in [int(x) for x in input().split()]:
        if not l[j-1]:
            l[j-1] = True
print(["NO","YES"][min(l)])


n,m=map(int,input().split())
p=(m*(m+1))//2
l=[]
for i in range(n):
    l += list(map(int, input().split()))[1:]
print('YES' if len(set(l)) == m else 'NO')


from itertools import chain
n,m=map(int,input().split())
l=[]
for i in range(n):
    n=list(map(int,input().split()))
    l.append(n)
a=list(chain.from_iterable(l))
a=set(a)
s=sum(a)
p=(s//2)-1
if(p==m):
    print("YES")
else:
    print("NO")


n,m=map(int,input().split())
p=(m*(m+1))//2
l=[]
for i in range(n):
    l += list(map(int, input().split()))[1:]
print('YES' if len(set(x)) == n else 'NO')


from itertools import chain
n,m=map(int,input().split())
p=(m*(m+1))//2
l=[]
for i in range(n):
    n=list(map(int,input().split()))
    l.append(n)
a=list(chain.from_iterable(l))
a=set(a)
s=sum(a)
if(p==s):
    print("YES")
else:
    print("NO")


# -*- coding: utf-8 -*-
"""
Created on Tue Nov  3 13:57:19 2020

@author: 86133
"""

n, m = map(int, input().split())
c = 1
d = [0 for i in range(200)]
for i in range(n):
    a = [int(j) for j in input().split()]
    for j in a[1:]:
        d[j] = 1
for i in d[1:m+1]:
    if not i:
        c = 0
        print('NO')
        break
if c:
    print('YES')


n, m = map(int, input().split())
x=[[int(i) for i in input().split()] for j in range(n)]
s=[]

for i in x:
  k=[]
  h=1
  for j in range(len(i)-1):
    if i[j]==i[j+1]:
       h+=1
    elif i[j]!=i[j+1]:
       if h>1:
         k.append(h%2)
       h=1

  #print(k)
  if 0 not in k:
     t=set(i)
     s=s+list(t)
     k=[]

s=list(set(s))
if 0 in s:
   if len(s)==m+1:
      print("YES")
else:
     if len(s)==m:
        print("YES")
     else:
        print("NO")


n, m = map(int, input().split())
x=[[int(i) for i in input().split()] for j in range(n)]
s=[]
h=1
k=[]
for i in x:
  for j in range(len(i)-1):
    if i[j]==i[j+1]:
       h+=1
    elif i[j]!=i[j+1]:
       if h>1:
         k.append(h%2)
         h=0
  #print(k)
  if 0 not in k:
     t=set(i)
     s=s+list(t)
     k=[]
  else:
    k=[]

s=list(set(s))
if 0 in s:
   if len(s)==m+1:
      print("YES")
elif 0 not in s:
  if len(s)==m:
      print("YES")
  else:
      print("NO")


n, m = map(int, input().split())
x=[[int(i) for i in input().split()] for j in range(n)]
s=[]
for i in x:
  k=[]
  h=1
  for j in range(len(i)-1):
    if i[j]==i[j+1]:
       h+=1
    elif i[j]!=i[j+1] or j==len(i)-1:
       if h>1:
         k.append(h%2)
       else:
         h=1
         k=[]
  if 0 not in k:
     t=set(i)
     s=s+list(t)
  else:
      k=[]
      h=1
s=list(set(s))
#print(s)
if 0 in s:
   if len(s)==m+1:
      print("YES")
   else:
     print("NO")
else:
     if len(s)==m:
        print("YES")
     else:
        print("NO")


n, m = map(int, input().split())
x=[[int(i) for i in input().split()] for j in range(n)]
s=[]

for i in x:
  if i==[0]:
    continue
  k=[]
  h=1
  for j in range(len(i)-1):
    if i[j]==i[j+1]:
       h+=1
    elif i[j]!=i[j+1] or j==len(i)-1:
       if h>1:
         k.append(h%2)
         h=1
       else:
         h=1
  if 0 not in k:
     t=set(i)
     s=s+list(t)
     k=[]
     h=1
  else:
      k=[]
      h=1
s=list(set(s))
#print(s)
if 0 in s:
   if len(s)==m+1:
      print("YES")
   else:
     print("NO")
else:
     if len(s)==m:
        print("YES")
     else:
        print("NO")


n, m = map(int, input().split())
x=[[int(i) for i in input().split()] for j in range(n)]
s=[]
h=0
for i in x:
  for j in range(len(i)-1):
    if i[j]==i[j+1]:
       h=1
  t=set(i)
  s=s+list(t)
s=list(set(s))
if len(s)==m and h<1:
  print("YES")
else:
  print("NO")


n, m = map(int, input().split())
x=[]
for i in range(n):
    x += list(map(int, input().split()))[1:]
print('YES' if len(set(x)) == m else 'NO')


n, m = map(int, input().split())
x=[[int(i) for i in input().split()] for j in range(n)]
s=[]
k=[]
h=1
for i in x:
  for j in range(len(i)-1):
    if i[j]==i[j+1]:
       h+=1
    else:
       if h>1:
         k.append(h%2)
       h=1
       k=[]
  if 0 not in k:
     t=set(i)
     s=s+list(t)
  else:
      k=[]
      h=1
s=list(set(s))
if 0 in s:
   if len(s)==m+1:
      print("YES")
   else:
     print("NO")
else:
     if len(s)==m:
        print("YES")
     else:
        print("NO")


n, m = map(int, input().split())
x=[[int(i) for i in input().split()] for j in range(n)]
s=[]
for i in x:
  t=set(i)
  s=s+list(t)
s=list(set(s))
if len(s)==m:
  print("YES")
else:
  print("NO")


n, m = map(int, input().split())
x=[[int(i) for i in input().split()] for j in range(n)]
s=[]
for i in x:
  k=[]
  h=1
  for j in range(len(i)-1):
    if i[j]==i[j+1]:
       h+=1
    else:
       if h>1:
         k.append(h%2)
       h=1
       k=[]
  if 0 not in k:
     t=set(i)
     s=s+list(t)
s=list(set(s))
if 0 in s:
   if len(s)==m+1:
      print("YES")
   else:
     print("NO")
else:
     if len(s)==m:
        print("YES")
     else:
        print("NO")


n, m = map(int, input().split())
x=[[int(i) for i in input().split()] for j in range(n)]
s=[]
k=[]
h=1
for i in x:
  for j in range(len(i)-1):
    if i[j]==i[j+1]:
       h+=1
    else:
       if h>1:
         k.append(h%2)
       else:
         h=1
         k=[]
  if 0 not in k:
     t=set(i)
     s=s+list(t)
  else:
      k=[]
      h=1
s=list(set(s))
if 0 in s:
   if len(s)==m+1:
      print("YES")
   else:
     print("NO")
else:
     if len(s)==m:
        print("YES")
     else:
        print("NO")


n, m = map(int, input().split())
x=[[int(i) for i in input().split()] for j in range(n)]
s=[]
for i in x:
  k=[]
  h=1
  for j in range(len(i)-1):
    if i[j]==i[j+1]:
       h+=1
    elif i[j]!=i[j+1] or j==len(i)-1:
       if h>1:
         k.append(h%2)
       h=1
       k=[]

  if 0 not in k:
     t=set(i)
     s=s+list(t)
  else:
      k=[]
      h=1
s=list(set(s))
print(s)
if 0 in s:
   if len(s)==m+1:
      print("YES")
   else:
     print("NO")
else:
     if len(s)==m:
        print("YES")
     else:
        print("NO")


n, m = map(int, input().split())
x=[[int(i) for i in input().split()] for j in range(n)]
s=[]
k=[]
h=1
for i in x:
  if i==[0]:
    continue
  for j in range(len(i)-1):
    if i[j]==i[j+1]:
       h+=1
    elif i[j]!=i[j+1] or j==len(i)-1:
       if h>1:
         k.append(h%2)
         h=1
       else:
         h=1
  if 0 not in k:
     t=set(i)
     s=s+list(t)
     k=[]
     h=1
  else:
      k=[]
      h=1
s=list(set(s))
#print(s)
if 0 in s:
   if len(s)==m+1:
      print("YES")
   else:
     print("NO")
else:
     if len(s)==m:
        print("YES")
     else:
        print("NO")


n, m = map(int, input().split())
x=[[int(i) for i in input().split()] for j in range(n)]
s=[]
l=0

for i in x:
  if len(i)>m:
     s+=[1000]
     break
  else:
     t=set(i)
     s=s+list(t)
s=list(set(s))
if 0 in s:
   if len(s)==m+1:
      print("YES")
elif 0 not in s:
  if len(s)==m:
      print("YES")
  else:
      print("NO")


n, m = map(int, input().split())
x=[[int(i) for i in input().split()] for j in range(n)]
s=[]
h=1
k=[]
for i in x:
  for j in range(len(i)-1):
    if i[j]==i[j+1]:
       h+=1
    elif i[j]!=i[j+1]:
       if h>1:
         k.append(h%2)
         h=0
  #print(k)
  if 0 not in k:
     t=set(i)
     s=s+list(t)
s=list(set(s))
if 0 in s:
   if len(s)==m+1:
      print("YES")
elif 0 not in s:
  if len(s)==m:
      print("YES")
  else:
      print("NO")


n, m = map(int, input().split())
x=[[int(i) for i in input().split()] for j in range(n)]
s=[]
h=1

for i in x:
  k=[]
  for j in range(len(i)-1):
    if i[j]==i[j+1]:
       h+=1
    elif i[j]!=i[j+1]:
       if h>1:
         k.append(h%2)
         h=1
  #print(k)
  if 0 not in k:
     t=set(i)
     s=s+list(t)
     k=[]

s=list(set(s))
if 0 in s:
   if len(s)==m+1:
      print("YES")
elif 0 not in s:
  if len(s)==m:
      print("YES")
  else:
      print("NO")


n, m = map(int, input().split())
x=[[int(i) for i in input().split()] for j in range(n)]
s=[]
for i in x:
  k=[]
  h=1
  for j in range(len(i)-1):
    if i[j]==i[j+1]:
       h+=1
    elif i[j]!=i[j+1] or j==len(i)-1:
       if h>1:
         k.append(h%2)
       h=1
       k=[]

  if 0 not in k:
     t=set(i)
     s=s+list(t)
  else:
      k=[]
      h=1
s=list(set(s))
if 0 in s:
   if len(s)==m+1:
      print("YES")
   else:
     print("NO")
else:
     if len(s)==m:
        print("YES")
     else:
        print("NO")


n, m = map(int, input().split())
x=[[int(i) for i in input().split()] for j in range(n)]
s=[]
for i in x:
  if i==[0]:
    continue
  k=[]
  h=1
  for j in range(len(i)-1):

    if i[j]==i[j+1]:
       h+=1
    elif i[j]!=i[j+1] or (j==len(i)-1 and h>1):
         k.append(h%2)
         h=1
  if 0 not in k:
     t=set(i)
     s=s+list(t)
     k=[]
     h=1
  else:
      k=[]
      h=1

s=list(set(s))
#print(s)
if 0 in s:
   if len(s)==m+1:
      print("YES")
   else:
     print("NO")
else:
     if len(s)==m:
        print("YES")
     else:
        print("NO")


n, m = map(int, input().split())
x=[[int(i) for i in input().split()] for j in range(n)]
s=[]
for i in x:
  if i==[0]:
    continue
  k=[]
  h=1
  for j in range(len(i)-1):
    if i[j]==i[j+1]:
       h+=1
    elif i[j]!=i[j+1] or j==len(i)-1:
       if h>1:
         k.append(h%2)
       else:
         h=1
         k=[]
  if 0 not in k:
     t=set(i)
     s=s+list(t)
  else:
      k=[]
      h=1
s=list(set(s))
#print(s)
if 0 in s:
   if len(s)==m+1:
      print("YES")
   else:
     print("NO")
else:
     if len(s)==m:
        print("YES")
     else:
        print("NO")


n, m = map(int, input().split())
x=[[int(i) for i in input().split()] for j in range(n)]
s=[]
for i in x:
  if i==[0]:
    continue
  k=[]
  h=1
  for j in range(len(i)-1):
    if i[j]==i[j+1]:
       h+=1
    elif i[j]!=i[j+1] or j==len(i)-1:
       if h>1:
         k.append(h%2)
         h=1
       else:
         k=[]
  if 0 not in k:
     t=set(i)
     s=s+list(t)
     h=1
     k=[]
  else:
      k=[]
      h=1
s=list(set(s))
#print(s)
if 0 in s:
   if len(s)==m+1:
      print("YES")
   else:
     print("NO")
else:
     if len(s)==m:
        print("YES")
     else:
        print("NO")


n, m = map(int, input().split())
x=[[int(i) for i in input().split()] for j in range(n)]
s=[]
k=[]
h=1
for i in x:
  if i==[0]:
    continue
  for j in range(len(i)-1):
    if i[j]==i[j+1]:
       h+=1
    elif i[j]!=i[j+1] or j==len(i)-1:
       if h>1:
         k.append(h%2)
         h=1
         k=[]
       else:
         h=1
         k=[]
  if 0 not in k:
     t=set(i)
     s=s+list(t)
  else:
      k=[]
      h=1
s=set(s)
#print(s)
if 0 in s:
   if len(s)==m+1:
      print("YES")
   else:
     print("NO")
else:
     if len(s)==m:
        print("YES")
     else:
        print("NO")


n, m = map(int, input().split())
x=[[int(i) for i in input().split()] for j in range(n)]
s=[]
k=[]
h=1
for i in x:
  if i==[0]:
    continue
  for j in range(len(i)-1):
    if i[j]==i[j+1]:
       h+=1
    elif i[j]!=i[j+1] or j==len(i)-1:
       if h>1:
         k.append(h%2)
         h=1
         k=[]
       else:
         h=1
         k=[]
  if 0 not in k:
     t=set(i)
     s=s+list(t)
  else:
      k=[]
      h=1
s=list(set(s))
#print(s)
if 0 in s:
   if len(s)==m+1:
      print("YES")
   else:
     print("NO")
else:
     if len(s)==m:
        print("YES")
     else:
        print("NO")


n,m=[int(x) for x in input().split()]
b=[]
for i in range(m):
    b.append("OFF")
for j in range(n):
    o=[int(x) for x in input().split()]
    for k in range(1,o[0]+1):
        if b[o[k]-1]=="OFF":
            b[o[k]-1]="ON"
print("YES" if b.count("OFF")==0 else "NO")


a,b = map(int,input().split())
c = [0] * b
for i in range(a):
    n = [int(s) for s in input().split()]
    for j in range(1,len(n)):
        c[n[j]-1] = 1
if (0) in(c):
    print("NO")
else:
    print("YES")


n,m=list(map(int,input().split()))
c=[]
i=0
while i<n:
    a=list(map(int,input().split()))
    c+=a[1:]
    i+=1
i=0
c.sort()
c=set(c)
sum1=0
for x in c:
    if True:
        sum1 += x
sum2=m*(m+1)//2
if sum2==sum1:
    print("YES")
else:
    print("NO")


n,m=list(map(int,input().split()))
c=[]
i=0
while i<m:
    a=list(map(int,input().split()))
    for x in a:
        c.append(x)
    i+=1
i=1
t=1
while i<=n:
    s=c.count(i)
    if s==0:
        t=0
        break
    i+=1
if t==0:
    print("NO")
else:
    print("YES")


n,m=list(map(int,input().split()))
c=[]
i=0
while i<n:
    a=list(map(int,input().split()))
    c+=a
    i+=1
i=0
c.sort()
c=set(c)
sum1=0
for x in c:
    if True:
        sum1 += x
sum2=m*(m+1)//2
if sum2==sum1:
    print("YES")
else:
    print("NO")


# A. Bulbs

n, m = map(int, input().split())
bulbs_on = set()
for _ in range(n):
    b = list(map(int, input().split()))
    for x in b[1:]:
        bulbs_on.add(x)
tmp_st = {i for i in range(1, m + 1)}
if bulbs_on == tmp_st:
    print('YES\n')
else:
    print('NO\n')


# A. Bulbs

n, m = map(int, input().split())
bulbs_on = set()
for _ in range(n):
    b = list(map(int, input().split()))
    for x in b:
        bulbs_on.add(x)
tmp_st = {i for i in range(1, m + 1)}
if bulbs_on == tmp_st:
    print('YES\n')
else:
    print('NO\n')


n,m=map(int,input().split())
l=[]
for i in range(n):
    d=list(map(int,input().split()))
    for j in d[1:]:
        l.append(j)
if(len(set(l))==m):
    print("YES")
else:
    print("NO")


n,m=map(int,input().split())
l=[]
c=0
for u in range(n):
    d=list(map(int,input().split()))
    for i in d:
        if(i not in l):
            l.append(i)
            c=c+1
if(c==m):
    print("YES")
else:
    print("NO")


n,m=map(int,input().split())
b=0
l=[]
for i in range(n):
    a = list(map(int,input().split()))
    for x in a:
        l.append(x)
print (["NO","YES"][len(set(l))==m])


n,m=map(int,input().split())
b=0
l=[]
for i in range(n):
    a = list(map(int,input().split()))
    for x in range(1,a[0]+1):
        l.append(a[x])
print (["NO","YES"][len(set(l))==m])


n,m=map(int,input().split())
b=0
l=[]
for i in range(n):
    a = list(map(int,input().split()))
    for x in range(1,a[0]):
        l.append(a[x])
print (["NO","YES"][len(set(l))==m])


x,y=[int(a) for a in input().split()]
a=[]
for i in range(x):
   z=[int(a) for a in input().split()]
   for i in z:
       a.append(i)
if len(set(a))==y:
    print("YES")
else:
    print("NO")


x,y=[int(a) for a in input().split()]
a=[]
for i in range(x):
   z=[int(a) for a in input().split()]
   z.pop()
   for i in z:
       a.append(i)
if len(set(a))==y:
    print("YES")
else:
    print("NO")


x,y=[int(a) for a in input().split()]
a=[]
for i in range(x):
   z=[int(a) for a in input().split()]
   z.pop(0)
   for i in z:
       a.append(i)
if len(set(a))==y:
    print("YES")
else:
    print("NO")


n,m = map(int, input().split())
s = set()
for x in range(n):
    s = s.union(set(map(int, input().split())))
print('YES' if sum(s) == (1+m)*(m)/2 else 'NO')


n,m = map(int, input().split())
s = set()
for x in range(n):
    l = list(input().split())
    l = l[1:]
    s = s.union(set(map(int, l)))
print('YES' if sum(s) == (1+m)*(m)/2 else 'NO')


a, b = map(int,input().split())
every = []
for i in range(a):
    bulb = [int(x) for x in input().split()]
    for i in bulb:
        every.append(i)
outcome = set(every)
if len(outcome) == b:
    print('YES')
else:
    print('NO')


a, b = map(int,input().split())
every = []
for i in range(a):
    bulb = [int(x) for x in input().split()]
    bulb.remove(bulb[0])
    for i in bulb:
        every.append(i)
outcome = set(every)
if len(outcome) == b:
    print('YES')
else:
    print('NO')


n,m=map(int,input().split())
d=set()
for i in range(m):
    d|=set(map(int,input().split()))[1::]
if len(d)==n:
    print("YES")
else:
    print("NO")


a, b = map(int, input().split())
arr = []
for i in range(a):
    arr += input().split()[1:]
print('YES' if len(set(arr)) == b else 'NO')


n,m=[int(x) for x in input().split()]
s=set()
for i in range(n):
    x=[int(x) for x in input().split()]
    s.update(x[1:])
print(["NO","YES"][len(s)==m])


n,m=[int(x) for x in input().split()]
s=set()
for i in range(n):
    x=[int(x) for x in input().split()]
    s.update(x)
print(["NO","YES"][len(s)==m])


m, n = map(int, input().split())
bulbs = [0]*n
for i in range(m):
  switch = list(map(int,input().split()))
  for i in range(switch[0]):
    bulbs[switch[i+1]-1] =  1
if 0 in bulbs:
  print("NO")
else:
  print("YES")


n, m = map(int, input().split())
s = set()
for i in range(n):
    z, *a = map(int, input().split())
    s.update(a)

if len(s) == m:
    print('YES')
else:
    print('NO')


import sys
import math
import bisect

def main():
    n, m = map(int, input().split())
    s = set()
    for i in range(n):
        A = list(map(int, input().split()))
        s = s | set(A[1:])
    if len(s) == m:
        print('YES')
    else:
        print('NO')

if __name__ == "__main__":
    main()


n,m=map(int,input().split())
a=(m*(m+1))//2
li=[]
for i in range(n):
    li += list(map(int, input().split()))[1:]
print('YES' if len(set(li)) == m else 'NO')


o = input().split()
n = int(o[0])
m = int(o[1])
b = [1] + [0] * m
for i in range(n):
    x = input().split()
    del x[0]
    for j in x:
        b[int(j)] = 1
if 0 in b:
    print("NO")
else:
    print("YES")


o = input()
n = int(o[0])
m = int(o[2:])
b = [1] + [0] * m
for i in range(n):
    x = input().split()
    del x[0]
    for j in x:
        b[int(j)] = 1
if 0 in b:
    print("NO")
else:
    print("YES")


o = input()
n = int(o[0])
m = int(o[2])
b = [1] + [0] * m
for i in range(n):
    x = input().split()
    del x[0]
    for j in x:
        b[int(j)] = 1
if 0 in b:
    print("NO")
else:
    print("YES")


n,m=[int(x) for x in input().split(' ')]
l=set()
z=[]
for _ in range(n):
    l=set([int(x) for x in input().split(' ')])
    for x in l:
        z.append(x)
a=set(z)
if len(a)==m:
    print('YES')
else:
    print('NO')


n,m=[int(x) for x in input().split(' ')]
l=set()
z=[]
for _ in range(n):
    l=[int(x) for x in input().split(' ')]
    n1,l1=l[0],l[1:]
    for x in l1:
        z.append(x)
a=set(z)
if len(a)==m:
    print('YES')
else:
    print('NO')


s,b=[int(x) for x in input().split()]
l=[]
for i in range(s):
    k = [int(p) for p in input().split()]
    l+=k
if len(set(l)) == b:
    print('YES')
else:
    print('NO')


s,b=[int(x) for x in input().split()]
l=[]
for i in range(s):
    k = [int(o) for o in input().split()]
    l+=k[1:len(k)]
if len(set(l)) == b:
    print('YES')
else:
    print('NO')


s,b=[int(x) for x in input().split()]
l=[]
for i in range(s):
    k=[int(s) for s in input().split()]
    l.append(k)
if len(set(l)) == b:
    print('YES')
else:
    print('NO')


s,b=[int(x) for x in input().split()]
l=[]
for i in range(s):
    k = [int(p) for p in input().split()]
    for q in range(k[0]):
        l.append(k[i+1])
if len(set(l)) == b:
    print('YES')
else:
    print('NO')


if __name__ == '__main__':
    n,m = map(int, input().split())
    a = list()
    for _ in range(n):
        b = list(map(int, input().split()))
        a += b
    a = set(a)
    if len(a) == m:
        print("YES")
    else:
        print("NO")


if __name__ == '__main__':
    n,m = map(int, input().split())
    a = list()
    for _ in range(n):
        b = list(map(int, input().split()))
        a += b[1:]
    a = set(a)
    if len(a) == m:
        print("YES")
    else:
        print("NO")


a,b=map(int,input().split())
s=set()
for i in range(a):
    l=list(map(int,input().split()))
    c=set(l)
    s=s.union(c)
if len(s)==b:
    print("YES")
else:
    print("NO")


a,b=map(int,input().split())
s=set()
for i in range(a):
    l=list(map(int,input().split()))
    l.remove(l[0])
    c=set(l)
    s=s.union(c)
if len(s)==b:
    print("YES")
else:
    print("NO")


def check(xx,m):
    for i in range(1,m+1):
        if str(i) not in set(xx):
            return False
    return True

n,m = map(int,input().split())
l = []
for i in range(n):
    l.append(input().split(" "))
ff = [j for i in l for j in i]
if check(ff,m):
    print("YES")
else:
    print("NO")


def check(xx,m):
    for i in range(1,m+1):
        if str(i) not in set(xx):
            return False
    return True

n,m = map(int,input().split())
l = []
for i in range(n):
    l.append(input().split(" "))
ff = [j for i in l for j in i[1:]]
if check(ff,m):
    print("YES")
else:
    print("NO")


n,m=map(int,input().split())
l=[i+1 for i in range(m)]
for i in range(n):
    x=[int(i) for i in input().split()]
    for i in range(len(x)):
        if x[i] in l[:]:
            l.remove(x[i])
if len(l)==0:
    print("YES")
else:
    print("NO")


n,m=map(int,input().split())
l=[i+1 for i in range(m)]
for i in range(n):
    x=[int(i) for i in input().split()]
    for i in range(len(x)-1):
        if x[i+1] in l[:]:
            l.remove(x[i+1])
if len(l)==0:
    print("YES")
else:
    print("NO")


n, m = map(int, input().split())
s = set()
for i in range(n):
    l = list(map(int, input().split()))
    if len(l) > 1:
        for j in range(1, len(l)):
            s.add(l[j])
if len(s) == m:
    print('YES')
else:
    print('NO')


n, m = map(int, input().split())
s = set()
for _ in range(n):
   for c in list(map(int, input().split()))[1:]:
       s.add(c)
print("YES" if (len(s) == m) else "NO")


n, m = tuple(map(int, input().split()))

turned = set()
for i in range(n):
    lamps = list(map(int, input().split()))
    for j in range(lamps[0]):
        turned.add(lamps[j + 1])

if len(turned) == m:
    print("YES")
else:
    print("NO")


n, m = map(int, input().split())
s = set()
for i in range(n):
	s |= set(input().split()[1:])
print("YES" if len(s) == m else "NO")


n, m = map(int, input().split())
a = []
e = 0

for i in range(n):
    l = list(map(int, input().split()))
    a += l[1:]
    b = list(set(a))

for j in range(1, m+1):
    if j in b:
        e += 1

if e == m:
    print("YES")
else:
    print("NO")


n, m = map(int, input().split())
a = []
e = 0

for i in range(n):
    l = list(map(int, input().split()))
    a += l
    b = list(set(a))

for j in range(1, m+1):
    if j in b:
        e += 1

if e == m:
    print("YES")
else:
    print("NO")


n, m = [int(x) for x in input().split()]
li = []
for i in range(n):
    l = list(map(int, input().split()))
    l.pop(0)
    for i in l: li.append(i)
li = set(li)
if len(li) == m: print("YES")
else: print("NO")


n,m=map(lambda x:int(x),input().split())
l=[]
for i in range(n):
    num=input()
    list=[int(i) for i in num.split()]
    for i in list[1:]:
        if i not in l:
            l.append(i)
if len(l)<m:
    print("NO")
else:
    print("YES")


n, m = [int(x) for x in input().split(' ')]
y = list(range(1, m + 1))
for i in range(n):
  k, *a = [int(x) for x in input().split(' ')]
  for x in a:
    if x in y: y.remove(x)
if len(y) == 0:
  print('YES')
else:
  print('NO')


n, m = map(int, input().split())
res = set.union(*(set(map(int, input().split())) for _ in range(n)))
print("YES" if len(res) == m else "NO")


n, m = map(int, input().split())
res = set.union(*(set(map(int, input().split()[1:])) for _ in range(n)))
print("YES" if len(res) == m else "NO")


import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
	PrintWriter out = new PrintWriter(System.out);
	BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer tok = new StringTokenizer("");
    String next() throws IOException {
        if (!tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); }
        return tok.nextToken();
    }
    int ni() throws IOException { return Integer.parseInt(next()); }
    long nl() throws IOException { return Long.parseLong(next()); }

    void solve() throws IOException {
        int n=ni(),c=ni();
        int[]A=new int[n];
        int[]B=new int[n];
        for (int x=1;x<n;x++) A[x]=ni();
        for (int x=1;x<n;x++) B[x]=ni();

        out.print("0 ");
        long d=c;
        long p=0;

        for (int x=1;x<n;x++) {
            long a=p+A[x];
            long b=p+c+B[x];
            d+=B[x];

            if (b<=a && b<=d) {
                out.print(b+" ");
                d=b;
                p=b;
                continue;
            }

            if (a<=d) { out.print(a+" "); p=a; }
            else { out.print(d+" "); p=d; }
        }
        out.println();
        out.flush();
    }

    public static void main(String[] args) throws IOException {
        new Main().solve();
    }
}


import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
	PrintWriter out = new PrintWriter(System.out);
	BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer tok = new StringTokenizer("");
    String next() throws IOException {
        if (!tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); }
        return tok.nextToken();
    }
    int ni() throws IOException { return Integer.parseInt(next()); }
    long nl() throws IOException { return Long.parseLong(next()); }

    void solve() throws IOException {
        int n=ni(),c=ni();
        int[]A=new int[n];
        int[]B=new int[n];
        for (int x=1;x<n;x++) A[x]=ni();
        for (int x=1;x<n;x++) B[x]=ni();

        out.print("0 ");
        int d=c;
        int p=0;

        for (int x=1;x<n;x++) {
            int a=p+A[x];
            int b=p+c+B[x];
            d+=B[x];

            if (b<=a && b<=d) {
                out.print(b+" ");
                d=b;
                p=b;
                continue;
            }

            if (a<=d) { out.print(a+" "); p=a; }
            else { out.print(d+" "); p=d; }
        }
        out.println();
        out.flush();
    }

    public static void main(String[] args) throws IOException {
        new Main().solve();
    }
}


import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
	PrintWriter out = new PrintWriter(System.out);
	BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer tok = new StringTokenizer("");
    String next() throws IOException {
        if (!tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); }
        return tok.nextToken();
    }
    int ni() throws IOException { return Integer.parseInt(next()); }
    long nl() throws IOException { return Long.parseLong(next()); }

    void solve() throws IOException {
        int n=ni(),c=ni();
        int[]A=new int[n];
        int[]B=new int[n];
        for (int x=1;x<n;x++) A[x]=ni();
        for (int x=1;x<n;x++) B[x]=ni();

        out.print("0 ");
        long d=c;
        long p=0;

        for (int x=1;x<n;x++) {
            long a=p+A[x];
            long b=p+c+B[x];
            d+=B[x];

            if (b<=a && b<=d) {
                out.print(b+" ");
                d=b;
                p=b;
                continue;
            }

            if (a<=d) { out.print(a+" "); p=a; }
            else { out.print(d+" "); p=d; }

            if (b<d) d=b;
        }
        out.println();
        out.flush();
    }

    public static void main(String[] args) throws IOException {
        new Main().solve();
    }
}


import java.util.Scanner;

public class Main {

	public static void main(String[] args)
	{
		Scanner s=new Scanner(System.in);

		int n=s.nextInt();
		int c=s.nextInt();

		int[] stair=new int[n-1];
		int[] elevator=new int[n-1];

		for(int i=0;i<n-1;i++)
		{
			stair[i]=s.nextInt();
		}

		for(int i=0;i<n-1;i++)
		{
			elevator[i]=s.nextInt();
		}

		int[][] dp=new int[n-1][2];

		dp[0][0]=stair[0];
		dp[0][1]=elevator[0];

		for(int i=1;i<n-1;i++)
		{
			if(stair[i]+dp[i-1][0]<=stair[i]+dp[i-1][1]+c)
			{
				dp[i][0]=stair[i]+dp[i-1][0];
			}
			else
			{
				dp[i][0]=stair[i]+dp[i-1][1]+c;
			}

			if(elevator[i]+dp[i-1][0]<=elevator[i]+dp[i-1][1])
			{
				dp[i][1]=elevator[i]+dp[i-1][0];
			}
			else
			{
				dp[i][1]=elevator[i]+dp[i-1][1];
			}

		}

		System.out.print(0+" ");

		for(int i=0;i<n-1;i++)
		{
			System.out.print(Math.min(dp[i][0],dp[i][1]+c)+" ");
		}

	}

}