#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long ar[n];
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
  }
  long long lc1 = 0, lc2 = 0;
  if (ar[0] == 2) {
    lc2++;
  } else {
    lc1++;
  }
  long long ans = 0;
  for (int i = 1; i < n; i++) {
    if (ar[i] == 2 and ar[i - 1] == 2) {
      lc2++;
    } else if (ar[i] == 1 and ar[i - 1] == 1) {
      lc1++;
    } else if (ar[i] == 1 and ar[i - 1] == 2) {
      lc1++;
    } else if (ar[i] == 2 and ar[i - 1] == 1) {
      ans = max(ans, 2 * min(lc1, lc2));
      lc2 = 1;
      lc1 = 0;
    }
  }
  if (ar[n - 1] == 1) {
    ans = max(ans, 2 * min(lc1, lc2));
  }
  lc1 = 0;
  lc2 = 0;
  if (ar[0] == 2) {
    lc2++;
  } else {
    lc1++;
  }
  for (int i = 1; i < n; i++) {
    if (ar[i] == 1 and ar[i - 1] == 1) {
      lc1++;
    } else if (ar[i] == 2 and ar[i - 1] == 2) {
      lc2++;
    } else if (ar[i] == 2 and ar[i - 1] == 1) {
      lc2++;
    } else if (ar[i] == 1 and ar[i - 1] == 2) {
      ans = max(ans, 2 * min(lc1, lc2));
      lc2 = 0;
      lc1 = 1;
    }
  }
  if (ar[n - 1] == 2) {
    ans = max(ans, 2 * min(lc1, lc2));
  }
  cout << ans;
  return 0;
}
