#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  vector<long long> arr(n);
  for (long long i = 0; i < n; i++) cin >> arr[i];
  long long t = 0, e = 0;
  long long best = 0;
  vector<long long> ans;
  arr.push_back(3);
  for (long long i = 0; i < n; i++) {
    t = 0;
    while (i < n && arr[i] == arr[i + 1]) {
      t++;
      i++;
    }
    t++;
    ans.push_back(t);
    i++;
    e = 0;
    while (i < n && arr[i] == arr[i + 1]) {
      e++;
      i++;
    }
    e++;
    ans.push_back(e);
  }
  for (long long i = 0; i < ans.size() - 1; i++) {
    best = max(best, min(ans[i], ans[i + 1]));
  }
  cout << best * 2 << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
