#include <bits/stdc++.h>
using namespace std;
int t[100010];
int vis[3] = {0};
int main() {
  int n;
  cin >> n;
  int num = 1;
  int numnum = 1;
  int maxn = 0;
  for (int i = 1; i <= n; i++) {
    cin >> t[i];
    if (!vis[t[i]]) vis[t[i]] = 1;
  }
  if (vis[1] == 0 || vis[2] == 0) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 2; i <= n; i++) {
    if (t[i] == t[i - 1]) {
      num++;
      if (min(num, numnum) * 2 > maxn) maxn = min(num, numnum) * 2;
    } else {
      numnum = num;
      num = 1;
      if (min(num, numnum) * 2 > maxn) maxn = min(num, numnum) * 2;
    }
  }
  cout << maxn << endl;
  return 0;
}
