#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long s = 0, t = 1;
  char ch = getchar();
  while (!isdigit(ch)) ch == '-' ? ch = getchar(), t = -1 : ch = getchar();
  while (isdigit(ch)) s = s * 10 + ch - '0', ch = getchar();
  return s * t;
}
long long n, a, b, x, y, ans;
int main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    x = read();
    if (x == y)
      x == 1 ? a++ : b++;
    else {
      if (x == 1) {
        ans = max(ans, min(a, b));
        a = 1;
      } else {
        ans = max(ans, min(a, b));
        b = 1;
      }
    }
    y = x;
  }
  ans = max(ans, min(a, b));
  printf("%lld", ans * 2);
  return 0;
}
