5362: Mr. Kitayuta, the Treasure Hunter

内存限制:256 MB 时间限制:2 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:3 通过:3

题目描述

C. Mr. Kitayuta, the Treasure Hunter
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output


Shuseki群岛是于坦波海中由30001个小岛组成的群岛。这些岛屿沿一条线均匀分布,从西到东,编号从0到30000。众所周知,这些岛屿蕴藏着许多珍宝。Shuseki群岛共有n颗宝石,第i颗宝石位于pi岛。
Kitayuta先生刚刚到达0号岛。凭借巨大的跳跃能力,他将按照以下过程在东面的岛屿之间重复进行跳跃:
首先,他将从0岛跳到d岛。
之后,他将根据以下规则继续跳跃。设l为上一跳的长度,也就是说,如果他上一跳是从岛屿prev跳到岛屿cur,则设l=cur prev。他将向东跳长度为l-1、l或l+1。也就是说,他将跳到岛(cur+l-1)、(cur+l)或(cur+l+1)(如果它们存在)。跳跃的长度必须是正的,也就是说,当l=1时,他不能执行长度为0的跳跃。如果没有有效的目的地,他将停止跳跃。
Kitayuta先生将在这个过程中收集所参观岛屿上的宝石。找到他可以收集的最大宝石数量。

输入
输入的第一行包含两个空格分隔的整数n和d(1≤n,d≤30000),分别表示Shuseki群岛的宝石数量和Kitayuta先生第一次跳跃的长度。
接下来的n行描述了宝石的位置。其中第i个(1≤i≤n)包含整数pi(d≤p1≤p2≤…≤pn≤30000),表示包含第i个宝石的岛的数量。
输出
打印Kitayuta先生可以收集的最大宝石数量。
提示
在第一个样本中,最佳路径为0→ 10(+1宝石)→ 19→ 27(+2宝石)→...
在第二个样本中,最佳路径为0→ 8.→ 15→ 21→ 28(+1宝石)→ 36(+1宝石)→ 45(+1宝石)→ 55(+1宝石)→ 66(+1宝石)→ 78(+1宝石)→...
在第三个样本中,最佳路径为0→ 7.→ 13→ 18(+1宝石)→ 24(+2宝石)→ 30(+1宝石)→...

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≤in) contains a integer pi (dp1p2≤...≤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) →...

输入格式

输出格式

输入样例 复制


输出样例 复制


数据范围与提示