#include <bits/stdc++.h>
using namespace std;
int place = 0;
int t[100000];
int solve(int p) {
  int i = p;
  while (t[i] == t[i + 1]) {
    i++;
  }
  int j = i + 1;
  place = i + 1;
  if (t[j] == 0) return 0;
  while (t[j] == t[j + 1]) j++;
  if (i - p + 1 < j - i)
    return i - p + 1;
  else
    return j - i;
}
int main(int argc, char const *argv[]) {
  int n, temp, lcs = 0;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> t[i];
  while (place < n) {
    temp = solve(place);
    if (temp > lcs) lcs = temp;
  }
  cout << lcs * 2;
  return 0;
}
