You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
514 B
C++

#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int n, pr = -1, cnt = 0;
cin >> n;
vector<int> v;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
if (i == 0) pr = x;
if (pr == x) cnt++;
else v.push_back(cnt), cnt = 1, pr = x;
}
v.push_back(cnt);
int ans = 0;
for (int i = 1; i < v.size(); i++)
ans = max(ans, min(v[i - 1], v[i]) * 2);
cout << ans;
return 0;
}