#include <bits/stdc++.h>
using namespace std;
const double ME = 2.71828;
const int N = 3e5 + 20;
const double pi = 3.141592653;
void LOSER() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
void file() { freopen("records.in", "r", stdin); }
long long gcd(long long a, long long b) { return (!b) ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long Fib_recur(long long n) {
  vector<long long> v(n + 5, 0);
  v[1] = 0;
  v[2] = 1;
  for (int i = int(3); i <= int(n); i++) v[i] = v[i - 1] + v[i - 2];
  return v[n];
}
bool isprime(int n) {
  for (int i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) return false;
  }
  return true;
}
void Solve() {
  int n, cnt = 1;
  cin >> n;
  vector<int> v(n), ans;
  for (auto& i : v) cin >> i;
  for (int i = 0; i < n - 1; i++) {
    if (v[i] == v[i + 1])
      cnt++;
    else {
      ans.push_back(cnt);
      cnt = 1;
    }
  }
  ans.push_back(cnt);
  int maxi = 0;
  for (int i = 0; i < ((int)(ans).size()) - 1; i++) {
    maxi = max(maxi, min(ans[i], ans[i + 1]));
  }
  cout << maxi * 2;
}
int main() {
  LOSER();
  Solve();
}
