#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, i, j = 0, prev = 0, next = 0, x, mx = 0, c = 0, k;
  cin >> n;
  long long int a[n];
  for (i = 0; i < n; i++) cin >> a[i];
  while (a[j] == a[j + 1] && j + 1 < n) j++;
  prev = j + 1;
  k = j + 1;
  next = 0;
  for (i = k; i < n; i++) {
    j = i;
    c = 0;
    while (a[j] == a[j + 1] && j + 1 < n) {
      c++;
      j++;
    }
    next = c + 1;
    x = min(prev, next);
    prev = next;
    if (x > mx) mx = x;
    i = j;
  }
  cout << 2 * mx << endl;
  return 0;
}
