#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<int> v;
  for (int i = 0; i < n; i++) {
    int j = i;
    while (a[j] == a[i]) j++;
    v.push_back(j - i);
    j--;
    i = j;
  }
  int maxi = INT_MIN;
  for (int i = 0; i < v.size() - 1; i++) maxi = max(maxi, min(v[i], v[i + 1]));
  cout << 2 * maxi;
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
