#include <bits/stdc++.h>
using namespace std;
long long mpow(long long base, long long exp) {
  base %= 1000000007;
  if (exp == 0) {
    return 0;
  }
  long long res = 1;
  while (exp > 0) {
    if (exp & 1) {
      res = (res * base) % 1000000007;
    }
    exp = exp >> 1;
    base = (base * base) % 1000000007;
  }
  return res;
}
long long sum(long long n) { return 5 * (long long)(n * (n + 1) / 2); }
long long update(long long ele, long long c) {
  if (ele == 1) {
    return c;
  } else {
    return -c;
  }
}
void sol() {
  long long n;
  cin >> n;
  vector<long long> arr(n);
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
  }
  vector<long long> temp(n, 0);
  long long c = 1, k = 0;
  for (long long i = 0; i < n - 1; i++) {
    if (arr[i] == arr[i + 1]) {
      c++;
    } else {
      temp[k] = update(arr[i], c);
      k++;
      c = 1;
    }
  }
  temp[k] = update(arr[n - 1], c);
  long long res = 0;
  for (long long i = 1; i < n && temp[i] != 0; i++) {
    if ((temp[i - 1] < 0 && temp[i] > 0) || (temp[i] < 0 && temp[i - 1] > 0)) {
      long long mn = min(abs(temp[i]), abs(temp[i - 1]));
      res = max(res, mn);
    }
  }
  cout << res * 2 << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  while (t--) {
    sol();
  }
  return 0;
}
