#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
struct edge {
  int v, nt;
} e[N << 1];
int h[N], cnt = 0;
inline void add(int u, int v) {
  e[++cnt] = (edge){v, h[u]};
  h[u] = cnt;
  e[++cnt] = (edge){u, h[v]};
  h[v] = cnt;
}
int x, y, z, na, nb, a[N], n, ans = 0;
int main() {
  scanf("%d", &n);
  nb = 0;
  ans = 0;
  a[0] = -1;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) {
    if (a[i] == a[i - 1]) {
      ++na;
      ans = max(ans, 2 * min(nb, na));
    } else {
      nb = na;
      na = 1;
      ans = max(ans, 2 * min(nb, na));
    }
  }
  printf("%d", ans);
  return 0;
}
