#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e5 + 7;
const long long int mod = 1e9 + 7;
long long binpow(long long a, long long b) {
  a %= mod;
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return res;
}
long long int n, arr[N];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  for (long long int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  long long int ans = 0, cnt = 1;
  std::vector<long long int> v;
  for (long long int i = 0; i < n - 1; i++) {
    if (arr[i] == arr[i + 1])
      cnt++;
    else {
      v.push_back(cnt);
      cnt = 1;
    }
  }
  v.push_back(cnt);
  for (long long int i = 0; i < v.size() - 1; i++) {
    if (ans < min(v[i], v[i + 1])) {
      ans = min(v[i], v[i + 1]);
    }
  }
  cout << 2 * ans << " ";
  return 0;
}
