#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long N = 1e5 + 7;
void init_code() {}
void yash() {
  long long n;
  cin >> n;
  long long a, b = 0, store = 0, mx = 0, count = 0;
  for (long long i = 0; i < n; i++) {
    cin >> a;
    if (a == b)
      count++;
    else {
      store = count;
      b = a;
      count = 1;
    }
    mx = max(mx, min(store, count));
  }
  cout << mx * 2 << endl;
}
signed main() {
  init_code();
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  yash();
  return 0;
}
