#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  int n;
  cin >> n;
  int ar[n + 10];
  vector<int> fr;
  fr.clear();
  for (int i = 1; i <= n; i++) cin >> ar[i];
  int sum = 1;
  for (int i = 2; i <= n; i++) {
    if (ar[i] == ar[i - 1])
      sum++;
    else {
      fr.push_back(sum);
      sum = 1;
    }
  }
  fr.push_back(sum);
  int pre = 0, max = -1;
  for (auto it : fr) {
    if (max < min(it, pre)) max = min(pre, it);
    pre = it;
  }
  cout << max * 2 << endl;
}
