#include <bits/stdc++.h>
using namespace std;
vector<long long> res;
int n;
long long a[1000001];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  long long t = a[1], sum = 0;
  a[n + 1] = 3;
  for (int i = 1; i <= n + 1; i++) {
    if (a[i] == t) {
      sum++;
    }
    if (a[i] != t) {
      res.push_back(sum);
      sum = 0;
      sum++;
      t = a[i];
    }
  }
  long long ans = 0;
  for (int i = 1; i < res.size(); i++) {
    ans = max(min(res[i], res[i - 1]), ans);
  }
  cout << ans * 2;
}
