#include <bits/stdc++.h>
using namespace std;
long long mM(long long a, long long b, long long mod) {
  long long res = 0;
  a %= mod;
  while (b) {
    if (b & 1) res = (res + a) % mod;
    a = (2 * a) % mod;
    b >>= 1;
  }
  return res;
}
long long fpow(long long first, long long second, long long p) {
  first = first % p;
  long long res = 1;
  while (second) {
    if (second & 1) res = (res * first) % p;
    res %= p;
    if (res < 0) res = (res + p) % p;
    second = second >> 1;
    first = (first * first) % p;
    if (first < 0) first = (first + p) % p;
    first %= p;
  }
  return res;
}
long long inv(long long n, long long p) { return fpow(n, p - 2, p); }
long long modmul(long long first, long long second) {
  return (first * second) % 1000000007;
}
long long modadd(long long first, long long second) {
  if (first >= 1000000007) first -= 1000000007;
  if (second >= 1000000007) second -= 1000000007;
  long long temp = first + second;
  if (temp >= 1000000007) temp -= 1000000007;
  if (temp < 0) temp = temp + 1000000007;
  return temp;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    long long n;
    cin >> n;
    vector<long long> a(n + 1);
    long long cnt1 = 0, cnt2 = 0;
    for (int i = 1; i <= n; i++) cin >> a[i];
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
      if (a[i] == 1) {
        if (a[i] != a[i - 1]) cnt1 = 0;
        cnt1++;
      } else {
        if (a[i] != a[i - 1]) cnt2 = 0;
        cnt2++;
      }
      ans = max(ans, min(cnt1, cnt2));
    }
    cout << 2 * ans << "\n";
  }
}
