#include <bits/stdc++.h>
using namespace std;
int main() {
  ios ::sync_with_stdio(false);
  cin.tie(0);
  ;
  long long int i, j = 0, n, o, m, l, p, k = 0, r, w, x = 0, y;
  vector<long long int> s, t, u;
  cin >> n;
  for (i = 0; i <= n - 1; i++) {
    cin >> r;
    if (i == 0) p = r;
    if (r == 2) {
      if (j > 0) s.push_back(j);
      j = 0;
      k++;
    } else {
      if (k > 0) t.push_back(k);
      k = 0;
      j++;
    }
  }
  if (j > 0) s.push_back(j);
  if (k > 0) t.push_back(k);
  while (t.size() > s.size()) s.push_back(0);
  while (t.size() < s.size()) t.push_back(0);
  l = t.size();
  for (i = 0; i <= l - 1; i++) {
    if (p == 2 && i != l - 1) {
      w = min(t[i + 1], s[i]);
      if (x < w) x = w;
    } else if (p == 1 && i != l - 1) {
      w = min(t[i], s[i + 1]);
      if (x < w) x = w;
    }
    w = min(t[i], s[i]);
    if (x < w) x = w;
  }
  cout << x * 2 << endl;
  return 0;
}
