#include <bits/stdc++.h>
using namespace std;
bool isPowerOfTwo(long long n) { return (ceil(log2(n)) == floor(log2(n))); }
long long binpow(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res *= a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  bool x = false;
  if ((a.second * a.first) < b.second * b.first) {
    x = true;
  }
  return x;
}
int main() {
  long long n;
  cin >> n;
  long long arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  vector<long long> v;
  long long x = 1;
  for (long long i = 0; i + 1 < n; i++) {
    if (arr[i] == arr[i + 1])
      x++;
    else {
      v.push_back(x);
      x = 1;
    }
  }
  v.push_back(x);
  long long now;
  long long best = 0;
  for (long long i = 0; i + 1 < v.size(); i++) {
    now = min(v[i], v[i + 1]);
    best = max(best, now);
  }
  cout << best * 2 << "\n";
}
