#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
int n;
vi a;
void input() {
  cin >> n;
  a.resize(n);
  for (auto&& i : a) cin >> i;
}
void solve() {
  vi cnt(n);
  for (int i = 0; i < n; ++i) {
    int j = i + 1;
    while (j < n && a[i] == a[j]) ++j;
    for (int k = i; k < j; ++k) cnt[k] = j - i;
    i = j - 1;
  }
  int ans = 0;
  for (int i = 0; i < n - 1; ++i) {
    if (a[i] != a[i + 1]) ans = max(ans, min(cnt[i], cnt[i + 1]) * 2);
  }
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(16);
  cout << fixed;
  int _times = 1;
  while (_times--) {
    input();
    solve();
  }
}
