#include <bits/stdc++.h>
using namespace std;
vector<long long int> vec;
int main() {
  ios_base::sync_with_stdio(false);
  long long int n, i, a[100005], k, c, ans = 0;
  cin >> n;
  for (i = 0; i < n; i++) cin >> a[i];
  k = a[0];
  c = 0;
  for (i = 0; i < n; i++) {
    if (a[i] != k) {
      vec.push_back(c);
      k = a[i];
      c = 0;
    }
    c++;
  }
  if (c > 0) {
    vec.push_back(c);
  }
  for (i = 0; i < vec.size() - 1; i++) {
    ans = max(ans, min(vec[i], vec[i + 1]) * 2);
  }
  cout << ans;
  return 0;
}
