#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;
#define MAXN 30100
int dp[MAXN][510];
int num[MAXN];
int main()
{
int n, m, val;
while(scanf("%d %d", &n, &m) != EOF)
{
memset(num ,0, sizeof(num));
for(int i = 0; i < n; i++)
{
scanf("%d",&val);
num[val]++;
}
memset(dp, -1, sizeof(dp));
dp[m][250] = num[m];
int ans = dp[m][250];
for(int i = m; i <= 30000; i++)
{
for(int j = 1; j <= 505; j++)
{
if(dp[i][j] == -1) continue;
int to = i + m + j - 250;
if(to <= 30000)
{
dp[to][j]= max(dp[to][j], dp[i][j] + num[to]);
ans = max(ans, dp[to][j]);
}
if(to + 1<= 30000)
{
dp[to+1][j+1]= max(dp[to+1][j+1], dp[i][j] + num[to+1]);
ans = max(ans, dp[to+1][j+1]);
}
if(to-1 <= 30000 &&m + j - 250 > 1)
{
dp[to-1][j-1]= max(dp[to-1][j-1], dp[i][j] + num[to-1]);
ans = max(ans, dp[to-1][j-1]);
}
}
}
printf("%d\n",ans);
}
return 0;
}
#include <string.h>
#include <stdio.h>
using namespace std;
#define MAXN 30100
int dp[MAXN][510];
int num[MAXN];
int main()
{
int n, m, val;
while(scanf("%d %d", &n, &m) != EOF)
{
memset(num ,0, sizeof(num));
for(int i = 0; i < n; i++)
{
scanf("%d",&val);
num[val]++;
}
memset(dp, -1, sizeof(dp));
dp[m][250] = num[m];
int ans = dp[m][250];
for(int i = m; i <= 30000; i++)
{
for(int j = 1; j <= 505; j++)
{
if(dp[i][j] == -1) continue;
int to = i + m + j - 250;
if(to <= 30000)
{
dp[to][j]= max(dp[to][j], dp[i][j] + num[to]);
ans = max(ans, dp[to][j]);
}
if(to + 1<= 30000)
{
dp[to+1][j+1]= max(dp[to+1][j+1], dp[i][j] + num[to+1]);
ans = max(ans, dp[to+1][j+1]);
}
if(to-1 <= 30000 &&m + j - 250 > 1)
{
dp[to-1][j-1]= max(dp[to-1][j-1], dp[i][j] + num[to-1]);
ans = max(ans, dp[to-1][j-1]);
}
}
}
printf("%d\n",ans);
}
return 0;
}