#include int h[100005], l; int comp_h(int a, int b) { if (h[a] > h[b]) return 1; else return -1; } void swap_h(int a, int b) { int f = h[a]; h[a] = h[b]; h[b] = f; return; } void push(int ne) { h[l] = ne; int p = l; l++; for (; p > 0; p = (p - 1) / 2) if (comp_h((p - 1) / 2, p) > 0) swap_h((p - 1) / 2, p); return; } int pop() { l--; swap_h(0, l); int p = 0; for (;;) { if (2 * p + 2 < l) { if (comp_h(2 * p + 1, 2 * p + 2) > 0) { if (comp_h(p, 2 * p + 2) > 0) swap_h(p, 2 * p + 2); p = 2 * p + 2; } else { if (comp_h(p, 2 * p + 1) > 0) swap_h(p, 2 * p + 1); p = 2 * p + 1; } } else if (2 * p + 1 < l) { if (comp_h(p, 2 * p + 1) > 0) swap_h(p, 2 * p + 1); p = 2 * p + 1; } else break; } return h[l]; } int main() { int n; scanf("%d", &n); int i; int a[100005]; for (i = 0; i < n; i++) scanf("%d", &a[i]); l = 0; for (i = 0; i < n; i++) push(a[i]); for (i = 0; i < n; i++) a[i] = pop(); int b[100005], c[100005], d = 1; b[0] = a[0]; c[0] = 1; for (i = 1; i < n; i++) { if (a[i] == b[d - 1]) c[d - 1]++; else { b[d] = a[i]; c[d] = 1; d++; } } int ans = 0; for (i = 0; i < d; i++) if (ans < c[i]) ans = c[i]; for (i = 0; i < d - 1; i++) if (b[i] + 1 == b[i + 1] && ans < c[i] + c[i + 1]) ans = c[i] + c[i + 1]; printf("%d\n", ans); return 0; }