#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  long long a[n + 5];
  long long o[n + 5];
  long long s[n + 5];
  memset(o, 0, sizeof(o));
  memset(s, 0, sizeof(s));
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  if (a[0] == 1) {
    o[0] += 1;
  }
  if (a[0] == 2) {
    s[0] += 1;
  }
  for (long long i = 1; i < n; i++) {
    if (a[i] == 1) {
      o[i] = o[i - 1] + 1;
    } else {
      s[i] = s[i - 1] + 1;
    }
  }
  deque<long long> d, v;
  for (long long i = 0; i <= n; i++) {
    if (o[i] == 0 && o[i - 1] != 0 && i > 0) {
      d.push_back(o[i - 1]);
    }
  }
  for (long long i = 0; i <= n; i++) {
    if (s[i] == 0 && s[i - 1] != 0 && i > 0) {
      v.push_back(s[i - 1]);
    }
  }
  long long l;
  if (a[0] == 2) {
    l = 0;
  } else {
    l = 1;
  }
  long long maxi = 0;
  while (!d.empty() && !v.empty()) {
    long long t = d.front();
    long long u = v.front();
    if (l % 2 == 1) {
      d.pop_front();
    }
    if (l % 2 == 0) {
      v.pop_front();
    }
    l++;
    maxi = max(maxi, min(t, u));
  }
  cout << maxi * 2;
}
