#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, ans;
int a[N], cnta[N], cntb[N];
template <typename T>
inline void chkmax(T &x, T y) {
  x = max(x, y);
}
template <typename T>
inline void chkmin(T &x, T y) {
  x = min(x, y);
}
template <typename T>
inline void read(T &x) {
  T f = 1;
  x = 0;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -f;
  for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
  x *= f;
}
int main() {
  read(n);
  for (register int i = 1; i <= n; ++i) {
    read(a[i]);
    if (a[i] == 1) {
      cnta[i] = cnta[i - 1] + 1;
      cntb[i] = cntb[i - 1];
    } else {
      cntb[i] = cntb[i - 1] + 1;
      cnta[i] = cnta[i - 1];
    }
  }
  for (register int i = 1; i <= n; ++i) {
    int l = i, r = n, sm, pos = i;
    int type = (a[i] == 1) ? 1 : 2;
    while (l <= r) {
      int mid = (l + r) >> 1;
      if (type == 1)
        sm = cnta[mid] - cnta[i - 1];
      else
        sm = cntb[mid] - cntb[i - 1];
      if (sm == mid - i + 1) {
        l = mid + 1;
        pos = mid;
      } else
        r = mid - 1;
    }
    if (type == 1)
      sm = cntb[2 * pos - i + 1] - cntb[pos];
    else
      sm = cnta[2 * pos - i + 1] - cnta[pos];
    if (sm == pos - i + 1) chkmax(ans, pos - i + 1);
  }
  ans <<= 1;
  printf("%d\n", ans);
  return 0;
}
