#include <bits/stdc++.h>
using namespace std;
bool check(int a[], int st, int end) {
  int l = (end + st) / 2;
  int a1 = a[st];
  int a2 = a[l + 1];
  if (a1 == a2) return false;
  for (int i = st + 1; i <= l; i++) {
    if (a[i] != a[i - 1]) return false;
  }
  for (int i = l + 2; i <= end; i++) {
    if (a[i] != a[i - 1]) return false;
  }
  return true;
}
int main() {
  int n;
  scanf("%d", &n);
  int a[n];
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  int ans = 2;
  vector<int> size;
  for (int i = 2; i <= n; i += 2) size.push_back(i);
  int low = 0, high = size.size() - 1;
  while (low <= high) {
    int mid = (low + high) / 2;
    int len = size[mid];
    int valid = 0;
    for (int i = len; i <= n; i++) {
      if (check(a, i - len, i - 1)) {
        valid = 1;
        break;
      }
    }
    if (valid) {
      ans = len;
      low = mid + 1;
    } else
      high = mid - 1;
  }
  printf("%d\n", ans);
}
