#include <bits/stdc++.h>
using ll = long long;
const ll N = 2 * 1e5 + 5;
const ll mod = 1e9 + 5;
const ll inf = 1e18;
const ll SZ = 101;
const double eps = 1e-9;
using namespace std;
void solve() {
  ll n;
  cin >> n;
  ll arr[n + 1], cnt[n + 1][3];
  memset(cnt, 0, sizeof(cnt));
  for (ll i = (n); i >= (1); i--) {
    cin >> arr[i];
  }
  ll lastseg = 0, currseg = 0;
  ll i = 0, ans = 0;
  ll x = arr[0];
  while (i < n) {
    while (i < n && arr[i] == x) {
      i++, currseg++;
      ans = max(ans, 2 * min(lastseg, currseg));
    }
    if (i == n) break;
    x = arr[i];
    lastseg = currseg;
    currseg = 0;
  }
  cout << ans;
}
int32_t main(int32_t argc, char *argv[]) {
  double t1 = clock();
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll TC = 1, t = 0;
  while (t++ < TC) {
    solve();
  }
  if (false)
    cerr << "Time : " << 1000 * (clock() - t1) / CLOCKS_PER_SEC << " ms\n";
  return 0;
}
