#include <bits/stdc++.h>
using namespace std;
template <typename T>
void out(T x) {
  cout << x << endl;
  exit(0);
}
const int maxn = 4e5 + 5;
int n, a[maxn], pref[maxn][3], suf[maxn][3];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    pref[i][a[i]] = 1;
    pref[i][a[i]] += pref[i - 1][a[i]];
  }
  for (int i = n; i >= 1; i--) {
    suf[i][a[i]] = 1;
    suf[i][a[i]] += suf[i + 1][a[i]];
  }
  int best = 0;
  for (int i = 1; i <= n; i++) {
    int one = min(pref[i][1], suf[i + 1][2]);
    int two = min(pref[i][2], suf[i + 1][1]);
    best = max(best, 2 * max(one, two));
  }
  out(best);
  return 0;
}
