Problem: The Shuseki Islands are an archipelago of 30001 small islands in the Yutampo Sea. The islands are evenly spaced along a line, numbered from 0 to 30000 from the west to the east. These islands are known to contain many treasures. There are n gems in the Shuseki Islands in total, and the i-th gem is located on island pi.

Mr. Kitayuta has just arrived at island 0. With his great jumping ability, he will repeatedly perform jumps between islands to the east according to the following process: 

  * First, he will jump from island 0 to island d. 
  * After that, he will continue jumping according to the following rule. Let l be the length of the previous jump, that is, if his previous jump was from island prev to island cur, let l = cur - prev. He will perform a jump of length l - 1, l or l + 1 to the east. That is, he will jump to island (cur + l - 1), (cur + l) or (cur + l + 1) (if they exist). The length of a jump must be positive, that is, he cannot perform a jump of length 0 when l = 1. If there is no valid destination, he will stop jumping. 



Mr. Kitayuta will collect the gems on the islands visited during the process. Find the maximum number of gems that he can collect.

Input

The first line of the input contains two space-separated integers n and d (1 ≤ n, d ≤ 30000), denoting the number of the gems in the Shuseki Islands and the length of the Mr. Kitayuta's first jump, respectively.

The next n lines describe the location of the gems. The i-th of them (1 ≤ i ≤ n) contains a integer pi (d ≤ p1 ≤ p2 ≤ ... ≤ pn ≤ 30000), denoting the number of the island that contains the i-th gem.

Output

Print the maximum number of gems that Mr. Kitayuta can collect.

Examples

Input

4 10
10
21
27
27


Output

3


Input

8 8
9
19
28
36
45
55
66
78


Output

6


Input

13 7
8
8
9
16
17
17
18
21
23
24
24
26
30


Output

4

Note

In the first sample, the optimal route is 0  →  10 (+1 gem)  →  19  →  27 (+2 gems)  → ...

In the second sample, the optimal route is 0  →  8  →  15  →  21 →  28 (+1 gem)  →  36 (+1 gem)  →  45 (+1 gem)  →  55 (+1 gem)  →  66 (+1 gem)  →  78 (+1 gem)  → ...

In the third sample, the optimal route is 0  →  7  →  13  →  18 (+1 gem)  →  24 (+2 gems)  →  30 (+1 gem)  → ...

Solution (in JAVA):

Solution:

import java.util.*;
import java.lang.*;
import java.io.*;

public class CO_505C {
	static int imax = Integer.MAX_VALUE, imin = Integer.MIN_VALUE;
	static long lmax = Long.MAX_VALUE, lmin = Long.MIN_VALUE;
	static long mod = (long) 1e9 + 7;

	static int n, d, max, islands[];

	static LinkedList<Integer> list[];
	static boolean visited[];
	static File infile = new File("input.txt");
	static File outfile = new File("output.txt");
	static InputReader in = new InputReader(System.in);
	static PrintWriter out;

	public static void main(String[] args) throws java.lang.Exception {
		// int test=in.ni();
		out = new PrintWriter(outfile);
		int test = 1;
		while (test-- > 0) {
			n = in.ni();
			d = in.ni();
			islands = new int[30005];
			int limit = 30005;
			for (int i = 0; i < n; i++) {
				int tmp = in.ni();
				islands[tmp]++;
				max = Math.max(tmp, max);
			}
			int dp[][] = new int[30005][500];
			int base = 250;
			for (int i = 30003; i >= 0; i--) {
				for (int j = 1; j + 1 < 500; j++) {
					int ans = 0;
					int x = 10;
					if (i + d + (base - j) - 1 < limit && i + d + (base - j) - 1 > 1) {
						// if (i == x)
						// out.print(
						// j + " " + (i + d + (base - j) - 1) + " " + dp[i + d +
						// (base - j) - 1][j + 1] + " ");
						ans = Math.max(ans, dp[i + d + (base - j) - 1][j + 1]);
					}
					if (i + d + (base - j) < limit && i + d + (base - j) > 1) {
						// if (i == x)
						// out.print(i + d + (base - j) + " " + dp[i + d + (base
						// - j)][j] + " ");
						ans = Math.max(ans, dp[i + d + (base - j)][j]);
					}
					if (i + d + (base - j) + 1 < limit && i + d + (base - j) + 1 > 1) {
						// if (i == x)
						// out.println(i + d + (base - j) + 1 + " " + dp[i + d +
						// (base - j) + 1][j - 1]);
						ans = Math.max(ans, dp[i + d + (base - j) + 1][j - 1]);
					}
					dp[i][j] = ans + islands[i];
					if (i == x) {
						// out.println("ans " + dp[i][j] + " " + j);
						// out.println();
					}
				}
			}
			// out.println(
			// islands[d] + Math.max(dp[d + d - 1][base - 1], Math.max(dp[d + d
			// + 1][base + 1], dp[d + d][base])));
			System.out.println(dp[d][base]);
		}
		out.close();
	}

	static HashMap<Pair, Integer> hmap = new HashMap<>();

	static int collect(int prevl, int cur) {
		if (prevl == 0)
			return 0;
		if (cur > max)
			return 0;
		if (hmap.containsKey(new Pair(prevl, cur))) {
			// System.out.println("here");
			return hmap.get(new Pair(prevl, cur));
		}
		list[cur].add(prevl);

		int ans = collect(prevl - 1, cur + prevl - 1);
		ans = Math.max(collect(prevl, cur + prevl), ans);
		ans = Math.max(collect(prevl + 1, cur + prevl + 1), ans);

		hmap.put(new Pair(prevl, cur), ans + islands[cur]);
		return ans + islands[cur];
	}

	static class Pair {
		int x, y;

		/*
		 * (non-Javadoc)
		 * 
		 * @see java.lang.Object#hashCode()
		 */
		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + x;
			result = prime * result + y;
			return result;
		}

		/*
		 * (non-Javadoc)
		 * 
		 * @see java.lang.Object#equals(java.lang.Object)
		 */
		@Override
		public boolean equals(Object obj) {
			if (this == obj) {
				return true;
			}
			if (obj == null) {
				return false;
			}
			if (!(obj instanceof Pair)) {
				return false;
			}
			Pair other = (Pair) obj;
			if (x != other.x) {
				return false;
			}
			if (y != other.y) {
				return false;
			}
			return true;
		}

		Pair(int x, int y) {
			this.x = x;
			this.y = y;
		}

		public String toString() {
			return x + " " + y;
		}

	}

	static void print(int arr[], int len) {
		for (int i = 0; i < len; i++)
			out.print(arr[i] + " ");
		out.println();
	}

	static class InputReader {

		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int ni() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c & 15;
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nl() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c & 15;
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public String ns() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public char[] ncs() {
			return ns().toCharArray();
		}

		public String nLine() {
			int c = read();
			// while (c != '\n' && c != '\r' && c != '\t' && c != -1)
			// c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (c != '\n' && c != '\r' && c != '\t' && c != -1);
			return res.toString();
		}

		public static boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

	}

}