#include<bits/stdc++.h>
using namespace std;
int a[30003]={0};
int dp[30005][350];
int n,d;
int func(int curr,int l)
{
if(dp[curr][(abs(l-d))]!=-1)
{
return dp[curr][(abs(l-d))];
}
int tmp=0,tmp1=0,tmp2=0,tmp3=0;
if(curr+l-1<30001 && l>1)
tmp=func(curr+l-1,l-1);
if(curr+l<30001)
tmp1=func(curr+l,l);
if(curr+l+1<30001)
tmp2=func(curr+l+1,l+1);
tmp3=max(max(tmp1,tmp2),tmp);
return dp[curr][(abs(l-d))]=tmp3+a[curr];
}
int main()
{
int tmp;
scanf("%d%d",&n,&d);
for(int i=0;i<n;i++)
{
scanf("%d",&tmp);
//maxi=max(tmp,maxi);
a[tmp]++;
}
//cout<<a[55]<<a[67]<<a[78];
memset(dp,-1,sizeof(dp));
int ans=func(d,d)+a[0];
cout<<ans;
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKaW50IGFbMzAwMDNdPXswfTsKaW50IGRwWzMwMDA1XVszNTBdOwppbnQgbixkOwppbnQgZnVuYyhpbnQgY3VycixpbnQgbCkKewogIGlmKGRwW2N1cnJdWyhhYnMobC1kKSldIT0tMSkKICB7CiAgICByZXR1cm4gZHBbY3Vycl1bKGFicyhsLWQpKV07CiAgfQogIGludCB0bXA9MCx0bXAxPTAsdG1wMj0wLHRtcDM9MDsKICBpZihjdXJyK2wtMTwzMDAwMSAmJiBsPjEpCiAgICB0bXA9ZnVuYyhjdXJyK2wtMSxsLTEpOwogIGlmKGN1cnIrbDwzMDAwMSkKICAgIHRtcDE9ZnVuYyhjdXJyK2wsbCk7CiAgaWYoY3VycitsKzE8MzAwMDEpCiAgICB0bXAyPWZ1bmMoY3VycitsKzEsbCsxKTsKICB0bXAzPW1heChtYXgodG1wMSx0bXAyKSx0bXApOwogIHJldHVybiBkcFtjdXJyXVsoYWJzKGwtZCkpXT10bXAzK2FbY3Vycl07Cn0KaW50IG1haW4oKQp7CiAgaW50IHRtcDsKICBzY2FuZigiJWQlZCIsJm4sJmQpOwogIGZvcihpbnQgaT0wO2k8bjtpKyspCiAgewogICAgc2NhbmYoIiVkIiwmdG1wKTsKICAgIC8vbWF4aT1tYXgodG1wLG1heGkpOwogICAgYVt0bXBdKys7CiAgfQogIC8vY291dDw8YVs1NV08PGFbNjddPDxhWzc4XTsKICBtZW1zZXQoZHAsLTEsc2l6ZW9mKGRwKSk7CiAgaW50IGFucz1mdW5jKGQsZCkrYVswXTsKICBjb3V0PDxhbnM7CiAgcmV0dXJuIDA7Cn0=