Source Code
#include <iostream>

using namespace std;

int n, a[1000000];
int main(){
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);

	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	int ans = 0, mx = 0;
	for (int i = 0; i < n; ++i)
	{
		ans = 0;
		for (int j = i; j < n; ++j)
		{
			if (a[i] == a[j])
			{
				ans = (j - i) + 1;
				mx = max(mx, ans);
			}
		}
	}

	cout << mx;










	return 0;
}
Copy
Good Segment omarqwerty
GNU G++17
2059 ms
1.8 MB
Time Limit Exceeded