#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long ans = 2;
  long long lenc, lenp;
  lenc = 1;
  lenp = 0;
  for (long long i = 1; i < n; i++) {
    if (a[i] == a[i - 1]) {
      lenc++;
    } else {
      ans = max(ans, min(lenc, lenp) * 2);
      lenp = lenc;
      lenc = 1;
    }
  }
  ans = max(ans, min(lenc, lenp) * 2);
  cout << ans;
  return 0;
}
