#include <bits/stdc++.h>
using namespace std;
int n, rt, ra, ca, b;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int t;
    scanf("%d", &t);
    if (t != rt) {
      rt = t;
      ra = ca;
      ca = 0;
    }
    ca++;
    b = max(b, min(ra, ca) * 2);
  }
  printf("%d", b);
  return 0;
}
