#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  vector<int> v1;
  int cnt = 1;
  for (int i = 1; i < n; i++) {
    if (arr[i] != arr[i - 1]) {
      v1.push_back(cnt);
      cnt = 1;
    } else {
      cnt++;
    }
  }
  v1.push_back(cnt);
  int ans = 0;
  for (int i = 1; i < v1.size(); i++) {
    ans = max(ans, min(v1[i], v1[i - 1]));
  }
  cout << (2 * ans);
  return 0;
}
