#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> v;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (a == 2)
      v.push_back(-1);
    else
      v.push_back(1);
  }
  vector<int> arr;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if ((cnt > 0 && v[i] < 0) || (cnt < 0 && v[i] > 0)) {
      arr.push_back(cnt);
      cnt = v[i];
    } else
      cnt += v[i];
  }
  arr.push_back(cnt);
  int ans = 0;
  for (int i = 1; i < arr.size(); i++) {
    if ((arr[i] < 0 && arr[i - 1] > 0) || (arr[i] > 0 && arr[i - 1] < 0))
      ans = max(ans, min(abs(arr[i]), abs(arr[i - 1])));
  }
  cout << (ans << 1);
}
