#include <bits/stdc++.h>
using namespace std;
int x, w = 1;
int x1[100100], x2[100100] = {0};
int main() {
  cin >> x;
  x2[0] = 1;
  for (int i = 0; i < x; i++) {
    cin >> x1[i];
    if (i > 0) {
      if (x1[i] != x1[i - 1]) {
        w++;
        x2[w - 1] = 1;
      } else
        x2[w - 1]++;
    }
  }
  x2[0] = min(x2[0], x2[1]);
  for (int i = 0; i < w - 1; i++) {
    x2[i] = min(x2[i], x2[i + 1]);
  }
  x2[w - 1] = 0;
  sort(x2, x2 + w);
  cout << x2[w - 1] * 2 << "\n";
}
