#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
const long long MOD = 1000000007;
const double PI = 2 * acos(0.0);
int a[N], oF[N], oB[N], tF[N], tB[N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] == 1) {
      oF[i] += oF[i - 1] + 1;
    } else {
      tF[i] += tF[i - 1] + 1;
    }
  }
  for (int i = n; i >= 1; i--) {
    if (a[i] == 1) {
      oB[i] += oB[i + 1] + 1;
    } else {
      tB[i] += tB[i + 1] + 1;
    }
  }
  int ans = 0;
  for (int i = 2; i <= n; i++) {
    if (a[i] != a[i - 1]) {
      if (a[i] == 1)
        ans = max(ans, min(tF[i - 1], oB[i]));
      else
        ans = max(ans, min(oF[i - 1], tB[i]));
    }
  }
  cout << ans * 2 << '\n';
  return 0;
}
