#include <bits/stdc++.h>
using namespace std;
using namespace std;
const int INF = int(1e9), mod = 1000000007, N = int(1e5) + 5;
const long long BIG = 100000000000000;
const double PI = 3.141592653589793238463;
int n, a[N], m[N], b[N], ans;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] == a[i - 1]) {
      m[i] = m[i - 1] + 1;
    } else {
      m[i] = 1;
    }
  }
  for (int i = n; i >= 1; i--) {
    if (a[i] == a[i + 1]) {
      b[i] = b[i + 1];
    } else {
      b[i] = m[i];
    }
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] != a[i - 1]) {
      ans = max(ans, min(b[i], b[i - 1]) * 2);
    }
  }
  cout << ans;
}
