#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  vector<long> A;
  long N, L, R, Pre = 0, Answer = -1;
  cin >> N;
  A.resize(N + 2, 0);
  for (long i = 1; i <= N; ++i) cin >> A[i];
  A[N + 1] = -1;
  for (L = 1; L <= N; L = R) {
    for (R = L + 1; A[R] == A[L]; ++R)
      ;
    Answer = max(Answer, 2 * min(Pre, R - L));
    Pre = R - L;
    L = R;
  }
  cout << Answer;
  return 0;
}
