#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  map<int, int> m;
  int ans = 0, i = 0;
  while (i < n) {
    m[a[i]] = 0;
    while (i < n && a[i] == 1) {
      m[a[i]]++;
      i++;
    }
    ans = max(ans, min(m[1], m[2]));
    m[a[i]] = 0;
    while (i < n && a[i] == 2) {
      m[a[i]]++;
      i++;
    }
    ans = max(ans, min(m[1], m[2]));
  }
  cout << 2 * ans;
}
