#include <bits/stdc++.h>
void __check(const char* expr, const char* file, unsigned int line) {
  printf("%s:%u: failed check `%s'\n", file, line, expr);
  abort();
}
using namespace std;
template <typename T>
bool uin(T& a, T b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool uax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
int sz(const T& t) {
  return static_cast<int>(t.size());
}
template <typename T>
void shrink(std::vector<T>& v) {
  std::vector<T>(v).swap(v);
}
const bool DBG = false;
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> v(1 + n);
  for (int i = 0; i < (int)(n); ++i) {
    cin >> v[i];
    v[i]--;
  }
  v[n] = v[n - 1] ^ 1;
  int prev = v[0];
  array<int, 2> a;
  a.fill(0);
  a[prev]++;
  int res = 0;
  for (int i = 1; i <= n; ++i) {
    int value = v[i];
    if (value != prev) {
      if (a[value] > 0) {
        int opposite = value ^ 1;
        auto local_res = min(a[opposite], a[value]) * 2;
        res = max(local_res, res);
        a[value] = 0;
      }
    }
    a[value]++;
    prev = value;
  }
  cout << res << endl;
  return 0;
}
