#include <bits/stdc++.h>
using namespace std;
int cur1 = 0, cur2 = 0, ans = 0;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> v(n);
  for (long long i = 0; i < n; ++i) {
    cin >> v[i];
  }
  int prev;
  if (v[0] == 1) {
    prev = 1;
    cur1 = 1;
  } else {
    prev = 2;
    cur2 = 1;
  }
  for (int i = 1; i < n; i++) {
    if (v[i] == prev) {
      if (v[i] == 1) {
        cur1++;
      } else {
        cur2++;
      }
      ans = max(ans, min(cur1, cur2));
    } else {
      if (v[i] == 1)
        cur1 = 1;
      else
        cur2 = 1;
    }
    prev = v[i];
    ans = max(ans, min(cur1, cur2));
  }
  cout << ans * 2;
}
