#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, no = 1, in = 0, maxx = 0;
  cin >> n;
  int a[n], b[100000];
  cin >> a[0];
  int k = a[0];
  for (int i = 1; i < n; i++) {
    cin >> a[i];
    if (a[i] == k) {
      no++;
    } else {
      b[in] = no;
      if (in != 0) {
        int p = 2 * min(b[in], b[in - 1]);
        if (maxx < p) maxx = p;
      }
      in++;
      no = 1;
      k = a[i];
    }
  }
  b[in] = no;
  if (maxx < 2 * min(b[in], b[in - 1])) maxx = 2 * min(b[in], b[in - 1]);
  cout << maxx;
}
