#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e9 + 7;
const ll N = 1e5;
template <typename T>
void gdb(vector<T>& a) {
  for (const auto& e : a) cout << e << " ";
  cout << endl;
}
int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n);
  vector<int> b;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < n; i++) {
    int j = i + 1;
    while (j < n && a[j] == a[i]) j++;
    b.push_back(j - i);
    i = j - 1;
  }
  int ans = 0;
  for (size_t i = 1; i < b.size(); i++) {
    ans = max(ans, min(b[i - 1], b[i]));
  }
  printf("%d\n", ans * 2);
}
