#include<bits/stdc++.h>
using namespace std;
#define dd double
#define ll long long int
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define pr pair<ll,ll>
#define pri pair<pr,ll>
#define pir pair<ll,pr>
#define ppr pair<pr,pr>
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll INF=9e15;
ll mod=998244353;
ll solve(vector<ll> &v1,ll in1,ll curr,ll lower,vector<vector<ll> > &dp){
if(in1>=v1.size()) return 0;
ll val=curr-lower;
if(dp[in1][val]!=-1) return dp[in1][val];
ll ans1=0;
if(curr>1) ans1=solve(v1,in1+curr-1,curr-1,lower,dp);
ans1=max(ans1,solve(v1,in1+curr,curr,lower,dp));
ans1=max(ans1,solve(v1,in1+curr+1,curr+1,lower,dp));
dp[in1][val]=ans1+v1[in1];
return dp[in1][val];
}
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("opt.txt","w",stdout);
#endif
fastio;
ll te=1;
// cin>>te;
while(te--){
vector<ll> v1(30001);
ll n,d,i,j,t;
cin>>n>>d;
for(i=0;i<n;i++){
cin>>j;
v1[j]++;
}
ll lower=d-245;
vector<vector<ll> > dp(30001,vector<ll>(500,-1));
cout<<v1[0]+solve(v1,d,d,lower,dp)<<endl;
}
}
659E - New Reform | 1385B - Restore the Permutation by Merger |
706A - Beru-taxi | 686A - Free Ice Cream |
1358D - The Best Vacation | 1620B - Triangles on a Rectangle |
999C - Alphabetic Removals | 1634C - OKEA |
1368C - Even Picture | 1505F - Math |
1473A - Replacing Elements | 959A - Mahmoud and Ehab and the even-odd game |
78B - Easter Eggs | 1455B - Jumps |
1225C - p-binary | 1525D - Armchairs |
1257A - Two Rival Students | 1415A - Prison Break |
1271A - Suits | 259B - Little Elephant and Magic Square |
1389A - LCM Problem | 778A - String Game |
1382A - Common Subsequence | 1512D - Corrupted Array |
667B - Coat of Anticubism | 284B - Cows and Poker Game |
1666D - Deletive Editing | 1433D - Districts Connection |
2B - The least round way | 1324A - Yet Another Tetris Problem |