#include <bits/stdc++.h>
using namespace std;
int main() {
  long long i, j, k;
  int n;
  cin >> n;
  vector<long long> v(n);
  for (i = (0); i < (n); i++) cin >> v[i];
  vector<pair<long long, long long> > c;
  long long count = 1, val = v[0];
  for (i = (1); i < (n); i++) {
    if (val == v[i])
      count++;
    else {
      c.push_back(make_pair(val, count));
      count = 1;
      val = v[i];
    }
  }
  c.push_back(make_pair(val, count));
  long long ans = 0;
  for (i = (0); i < ((int)((c).size()) - 1); i++) {
    ans = max(ans, 2 * min(c[i].second, c[i + 1].second));
  }
  cout << ans << '\n';
  return 0;
}
