Source Code
#include <iostream>
using namespace std;


int main() {
//     freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
	
	int a[100000];
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	int ans = 0;
	int x = a[0], y = a[n-1];
	int l = 0, r = n - 1;
	for (int i = 0; i < n; ++i)
	{
		if (a[l+1] == x)
		{
			l++;
			ans++;
		}
		if (a[r-1] == y)
		{
			++ans;
			r--;
		}
	}
	cout << ans;
}
Copy
Pop Pop microwave6
GNU G++17
1 ms
620 KB
Wrong Answer
Test Case #1
1 ms
620 KB
Accepted
Input
5
11100
Output
3
Judge Output
3
Checker Message
"3"
Test Case #2
1 ms
568 KB
Wrong Answer
Input
10
1100010011
Output
8
Judge Output
9
Checker Message
1st words differ - expected: '9', found: '8'