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