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.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;

/*
public class _505C {

}

 */

public class _505C {

	int limit = 30000;
	class e
	{
		int s;
		int jl;
		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + getOuterType().hashCode();
			result = prime * result + jl;
			result = prime * result + s;
			return result;
		}
		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			e other = (e) obj;
			if (!getOuterType().equals(other.getOuterType()))
				return false;
			if (jl != other.jl)
				return false;
			if (s != other.s)
				return false;
			return true;
		}
		public e(int s, int jl) {
			super();
			this.s = s;
			this.jl = jl;
		}
		private _505C getOuterType() {
			return _505C.this;
		}
	}
	public void solve() throws FileNotFoundException {
		InputStream inputStream = System.in;

		InputHelper inputHelper = new InputHelper(inputStream);

		PrintStream out = System.out;

		//actual solution

		int n = inputHelper.readInteger();
		int d = inputHelper.readInteger();

		int[] p = new int[n];

		Map<Integer, Integer> gs = new HashMap<Integer, Integer>();
		for(int i = 0; i < n; i++)
		{
			p[i] = inputHelper.readInteger();
			if(gs.containsKey(p[i]))
			{
				gs.put(p[i], gs.get(p[i]) + 1);
			}
			else
			{
				gs.put(p[i], 1);
			}
		}

		
		/*int ans = Integer.MIN_VALUE;
		for(int i = d + 1; i <= limit; i++)
		{
			dp[i] = Integer.MIN_VALUE;
			if(m.get(i) != null)
			{
				for(Integer e : m.get(i))
				{
					dp[i] = Math.max(dp[i - e], dp[i]);
				}

				if(gs.containsKey(i))
				{
					dp[i] += gs.get(i);
					System.out.println(i + " " + gs.get(i) + " " + dp[i]);
				}

				ans = Math.max(ans, dp[i]);
			}
		}*/
		
		int[][] dp = new int[30001][501];
		
		for(int i = 0; i <= 30000; i++)
		{
			for(int j = 0; j <= 500; j++)
			{
				dp[i][j] = -50000;
			}
		}
		
		if(gs.containsKey(d))
		{
			dp[d][250] = gs.get(d);
		}
		else
		{
			dp[d][250] = 0;
		}
		
		int ans = dp[d][250];
		for(int i = d + 1; i <= 30000; i++)
		{
			for(int j = 0; j <= 500; j++)
			{
				int jump = d + (j - 250);
				
				if(jump <= 0)
					continue;
				
				int fi = i - jump;
				
				if(j > 0 && fi >= 0)
				{
					dp[i][j] = Math.max(dp[i][j], dp[fi][j - 1]);
				}
				if(fi >= 0)
				{
					dp[i][j] = Math.max(dp[i][j], dp[fi][j]);
				}
				if(j < 500 && fi >= 0)
				{
					dp[i][j] = Math.max(dp[i][j], dp[fi][j + 1]);
				}
				
				if(gs.containsKey(i))
				{
					dp[i][j] += gs.get(i);
				}
				
				ans = Math.max(ans, dp[i][j]);
			}
		}
		
		/*HashMap<Integer, Set<Integer>> m = new HashMap<Integer, Set<Integer>>();

		//e de = new e(0, d);

		Set<Integer> nel = new HashSet<Integer>();
		nel.add(d);
		m.put(d, nel);
		for(int i = d; i <= limit; i++)
		{
			//System.out.println(i + "...");
			if(m.get(i) != null)
			{
				List<Integer> l = new ArrayList<Integer>(m.get(i));
				//System.out.println(l.size() + "..");
				for(Integer e : l)
				{
					int jl1 = e - 1;
					int jl2 = e;
					int jl3 = e + 1;

					if(jl1 > 0 && i + jl1 <= limit)
					{
						//e ne = new e(i, jl1);

						if(m.get(i + jl1) == null)
						{
							Set<Integer> nel2 = new HashSet<Integer>();
							nel2.add(jl1);
							m.put(i + jl1, nel2);
						}
						else
						{
							m.get(i + jl1).add(jl1);
						}
					}

					if(jl2 > 0 && i + jl2 <= limit)
					{
						//e ne = new e(i, jl2);

						if(m.get(i + jl2) == null)
						{
							Set<Integer> nel2 = new HashSet<Integer>();
							nel2.add(jl2);
							m.put(i + jl2, nel);
						}
						else
						{
							m.get(i + jl2).add(jl2);
						}
					}

					if(jl3 > 0 && i + jl3 <= limit)
					{
						//e ne = new e(i, jl3);

						if(m.get(i + jl3) == null)
						{
							Set<Integer> nel2 = new HashSet<Integer>();
							nel2.add(jl3);
							m.put(i + jl3, nel);
						}
						else
						{
							m.get(i + jl3).add(jl3);
						}
					}
				}
			}
		}*/


		out.println(ans);
		//end here
	}

	public static void main(String[] args) throws FileNotFoundException {
		(new _505C()).solve();
	}

	class InputHelper {
		StringTokenizer tokenizer = null;
		private BufferedReader bufferedReader;

		public InputHelper(InputStream inputStream) {
			InputStreamReader inputStreamReader = new InputStreamReader(
					inputStream);
			bufferedReader = new BufferedReader(inputStreamReader, 16384);
		}

		public String read() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					String line = bufferedReader.readLine();
					if (line == null) {
						return null;
					}
					tokenizer = new StringTokenizer(line);
				} catch (IOException e) {
					e.printStackTrace();
				}
			}

			return tokenizer.nextToken();
		}

		public Integer readInteger() {
			return Integer.parseInt(read());
		}

		public Long readLong() {
			return Long.parseLong(read());
		}
	}
}