#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, an = 0;
  cin >> n;
  long long a[n];
  for (long long int i = 0; i < n; i++) cin >> a[i];
  long long x[3] = {0};
  x[a[0]]++;
  for (long long int i = 0; i < n - 1; i++) {
    if (a[i] != a[i + 1]) {
      x[a[i + 1]] = 1;
    } else
      x[a[i]]++;
    an = max(an, min(x[1], x[2]));
  }
  cout << an * 2;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long TESTS = 1;
  while (TESTS--) {
    solve();
  }
  return 0;
}
