#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
using namespace std;
const long long N = 1e5 + 7;
const long long INF = 1e9 + 7;
const int xi[] = {-1, +1, 0, 0};
const int yi[] = {0, 0, -1, +1};
const int p = 31;
int n, cnt, a[N], ans;
vector<int> v;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 2; i <= n; i++) {
    if (a[i] == a[i - 1]) {
      cnt++;
    } else {
      v.push_back(cnt + 1);
      cnt = 0;
    }
  }
  v.push_back(cnt + 1);
  if (v.size() == 1) {
    cout << 0;
    return 0;
  }
  for (int i = 1; i < v.size(); i++) {
    ans = max(ans, min(v[i], v[i - 1]));
  }
  cout << ans * 2;
}
