#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int x = 0, y = 0;
  for (int i = 0; i < n;) {
    int c1 = 0;
    while (i < n && a[i] == 1) {
      c1++;
      i++;
    }
    int c2 = 0;
    while (i < n && a[i] == 2) {
      c2++;
      i++;
    }
    x = max(x, min(c1, c2));
  }
  for (int i = 0; i < n;) {
    int c1 = 0;
    while (i < n && a[i] == 2) {
      c1++;
      i++;
    }
    int c2 = 0;
    while (i < n && a[i] == 1) {
      c2++;
      i++;
    }
    y = max(y, min(c1, c2));
  }
  int ans = max(x, y);
  cout << 2 * ans << endl;
}
