#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int t[n];
  for (int i = 0; i < n; i++) {
    cin >> t[i];
  }
  int pre[3] = {0}, num[3] = {0};
  int current = t[0], ans = 1, temp;
  for (int i = 0; i < n; i++) {
    if (t[i] != current) {
      pre[current] = num[current];
      temp = min(pre[1], pre[2]);
      ans = max(ans, temp);
      num[current] = 0;
      current = t[i];
    }
    num[current]++;
  }
  pre[current] = num[current];
  temp = min(pre[1], pre[2]);
  ans = max(ans, temp);
  ans *= 2;
  cout << ans;
}
