#include <bits/stdc++.h>
using namespace std;
long long int n, a[1111111], ans, l, sum, u[1111111], x[1111111], m;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (i > 1 && a[i] == a[i - 1]) {
      u[m]++;
    } else {
      ++m;
      x[m] = a[i];
      u[m] = 1;
    }
  }
  x[m + 1] = 9999999999;
  sum = u[1] + u[2];
  if (m <= 2) {
    ans = u[1] + u[2];
  }
  for (int i = 3; i <= m + 1; i++) {
    if (sum > ans) {
      ans = sum;
    }
    if (x[i] == x[i - 2]) {
      sum += u[i];
    } else {
      sum = u[i - 1] + u[i];
    }
  }
  cout << ans;
  return 0;
}
