#include <bits/stdc++.h>
using namespace std;
int m[200000], i, k, n, x = 1, y = 0, maxi;
int main() {
  cin >> n;
  for (i = 0; i < n; i++) cin >> m[i];
  for (i = 1; i < n; i++) {
    if (m[i] != m[i - 1]) {
      maxi = max(maxi, min(x, y));
      y = x;
      x = 1;
      if (k == 1) break;
    } else
      x++;
    if (i == n - 1 && m[0] == m[n - 1]) {
      i = 0;
      x++;
      k++;
    } else if (i == n - 1 && m[0] != m[n - 1]) {
      maxi = max(maxi, min(x, y));
      y = x;
      x = 1;
    }
  }
  cout << maxi * 2;
}
