#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  int b = 0, m = 0, k, l = 0;
  for (int i = 0; i < n; i++) {
    if (v[i] == b)
      m++;
    else {
      k = m;
      m = 1;
      b = v[i];
    }
    l = max(l, min(k, m));
  }
  cout << 2 * l;
}
