#include <bits/stdc++.h>
int sushi[100005], size1 = 1;
using namespace std;
bool check(int b) {
  int cnt = 0;
  for (int i = 0; i < size1; i++) {
    if (sushi[i] >= b) {
      cnt++;
      if (cnt == 2) return true;
    } else
      cnt = 0;
  }
  return false;
}
int main(int argc, char **argv) {
  ios::sync_with_stdio(false);
  int a, cnt = 0, temp = 0;
  cin >> a;
  for (int i = 0; i < a; i++) {
    int b;
    cin >> b;
    if (b != temp) {
      cnt++;
      temp = b;
      size1++;
    }
    sushi[cnt]++;
  }
  int l = 0;
  int r = a / 2;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      l = mid + 1;
    else
      r = mid - 1;
  }
  cout << r * 2 << endl;
  return 0;
}
