#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   int n, d, p[30005], dp1[60005][700];   int occ[30005];   int main() {     scanf( %d%d , &n, &d);     int xb, x2, x3;     for (xb = 0; xb < n; xb++) {       scanf( %d , &p[xb]);       p[xb]--;       occ[p[xb]]++;     }     d--;     int res = 0;     for (xb = 0; xb < 60005; xb++) {       for (x3 = 0; x3 < 700; x3++) dp1[xb][x3] = -inf;     }     dp1[d][350] = 0;     for (xb = d; xb < 30000; xb++) {       for (x3 = 0; x3 < 700; x3++) {         if (dp1[xb][x3] == -inf) continue;         int tv = d + x3 - 349, adg = occ[xb];         if (tv > 0)           res = (((res) > (adg + dp1[xb][x3])) ? (res) : (adg + dp1[xb][x3]));         if (tv > 1)           dp1[xb + tv - 1][x3 - 1] =               (((dp1[xb + tv - 1][x3 - 1]) > (dp1[xb][x3] + adg))                    ? (dp1[xb + tv - 1][x3 - 1])                    : (dp1[xb][x3] + adg));         if (tv > 0)           dp1[xb + tv][x3] =               (((dp1[xb + tv][x3]) > (dp1[xb][x3] + adg)) ? (dp1[xb + tv][x3])                                                           : (dp1[xb][x3] + adg));         if (tv > -1)           dp1[xb + tv + 1][x3 + 1] =               (((dp1[xb + tv + 1][x3 + 1]) > (dp1[xb][x3] + adg))                    ? (dp1[xb + tv + 1][x3 + 1])                    : (dp1[xb][x3] + adg));       }     }     printf( %d n , res);     return 0;   }   