#include <bits/stdc++.h>
using namespace std;
long long n, fg, minn, maxx;
int main() {
  vector<long long> v1, v2;
  cin >> n;
  long long a[n];
  cin >> a[0];
  if (a[0] == 1)
    v1.push_back(1);
  else
    v2.push_back(2);
  for (long long i = 1; i < n; i++) {
    cin >> a[i];
    if (a[i] == 1)
      v1.push_back(1);
    else
      v2.push_back(2);
    if (a[i] != a[i - 1]) {
      fg++;
      if (fg == 2) {
        fg = 1;
        if (a[i] == 1)
          v1.pop_back();
        else
          v2.pop_back();
        minn = min(v2.size(), v1.size());
        maxx = max(maxx, 2 * minn);
        if (a[i] == 1) {
          v1.clear();
          v1.push_back(1);
        } else {
          v2.clear();
          v2.push_back(2);
        }
      }
    }
  }
  minn = min(v2.size(), v1.size());
  maxx = max(maxx, 2 * minn);
  cout << maxx << endl;
  return 0;
}
