#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v;
  int x;
  int maxi = 0;
  for (int i = 0; i < n; i++) {
    cin >> x;
    v.push_back(x);
  }
  int k = 0;
  for (int i = 0; i < n;) {
    int g = 1;
    int h;
    for (int j = i + 1; j < n; j++) {
      int y = 0;
      if (v[j] == v[i]) {
        g++;
      } else {
        h = j;
        y++;
      }
      if (j == n - 1) {
        k++;
        break;
      }
      if (y == 1) {
        break;
      }
    }
    int u = 1;
    for (int j = h + 1; j < n; j++) {
      if (v[j] != v[i]) {
        u++;
      } else {
        break;
      }
    }
    if (u >= g) {
      if (maxi < g * 2) {
        maxi = g * 2;
      }
    } else {
      if (maxi < u * 2) {
        maxi = u * 2;
      }
    }
    i = h;
    if (k == 1) {
      break;
    }
  }
  cout << maxi;
  return 0;
}
