#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 55;
int n, a[N], f[N];
inline int read(){
int x = 0, sgn = 1;
char ch = getchar();
while (ch < '0' || ch > '9')
{
if (ch == '-') sgn = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
{
x = x * 10 + ch - '0';
ch = getchar();
}
return sgn * x;
}
int calc(int x, int y){
int i, k;
for (k = 1; k <= y - x + 1; ++k){
for (i = k; i <= y - x; ++i)
if (abs(a[i + x] - a[i + x - k]) > 1) return k - 1;
if (abs(a[x + k - 1] - a[y - k + 1]) <= 1) return k - 1;
}
return y - x + 1; }
int main(){
freopen("puppet.in","r",stdin);
freopen("puppet.out","w",stdout);
int i, j;
while (scanf("%d", &n) != EOF){
for (i = 1; i <= n; ++i)
scanf("%d", a + i);
sort(a + 1, a + n + 1);
memset(f, 0, sizeof(f));
for (i = 1; i <= n; ++i)
for (j = 0; j < i; ++j)
f[i] = max(f[i], f[j] + calc(j + 1, i));
printf("%d\n", f[n]);
}
return 0;
}