B - At Most 3 (Judge ver.) 解説 /

実行時間制限: 2 sec / メモリ制限: 1024 MB

配点 : 200

問題文

おもり 1, おもり 2, \dots, おもり NN 個のおもりがあります。おもり i の重さは A_i です。
以下の条件を満たす正整数 n良い整数 と呼びます。

  • \bf{3} 個以下 の異なるおもりを自由に選んで、選んだおもりの重さの和を n にすることができる。

W 以下の正整数のうち、良い整数は何個ありますか?

制約

  • 1 \leq N \leq 300
  • 1 \leq W \leq 10^6
  • 1 \leq A_i \leq 10^6
  • 入力される値はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

N W
A_1 A_2 \dots A_N

出力

答えを出力せよ。


入力例 1

2 10
1 3

出力例 1

3

おもり 1 のみを選ぶと重さの和は 1 になります。よって 1 は良い整数です。
おもり 2 のみを選ぶと重さの和は 3 になります。よって 3 は良い整数です。
おもり 1 とおもり 2 を選ぶと重さの和は 4 になります。よって 4 は良い整数です。
これら以外に良い整数は存在しません。また、1,3,4 のいずれも W 以下の整数です。よって答えは 3 個になります。


入力例 2

2 1
2 3

出力例 2

0

W 以下の良い整数は存在しません。


入力例 3

4 12
3 3 3 3

出力例 3

3

良い整数は 3,6,93 個です。
たとえばおもり 1, おもり 2, おもり 3 を選ぶと重さの和は 9 になるので、9 は良い整数です。
12 は良い整数 ではない ことに注意してください。


入力例 4

7 251
202 20 5 1 4 2 100

出力例 4

48

Score : 200 points

Problem Statement

There are N weights called Weight 1, Weight 2, \dots, Weight N. Weight i has a mass of A_i.
Let us say a positive integer n is a good integer if the following condition is satisfied:

  • We can choose at most 3 different weights so that they have a total mass of n.

How many positive integers less than or equal to W are good integers?

Constraints

  • 1 \leq N \leq 300
  • 1 \leq W \leq 10^6
  • 1 \leq A_i \leq 10^6
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N W
A_1 A_2 \dots A_N

Output

Print the answer.


Sample Input 1

2 10
1 3

Sample Output 1

3

If we choose only Weight 1, it has a total mass of 1, so 1 is a good integer.
If we choose only Weight 2, it has a total mass of 3, so 3 is a good integer.
If we choose Weights 1 and 2, they have a total mass of 4, so 4 is a good integer.
No other integer is a good integer. Also, all of 1, 3, and 4 are integers less than or equal to W. Therefore, the answer is 3.


Sample Input 2

2 1
2 3

Sample Output 2

0

There are no good integers less than or equal to W.


Sample Input 3

4 12
3 3 3 3

Sample Output 3

3

There are 3 good integers: 3, 6, and 9.
For example, if we choose Weights 1, 2, and 3, they have a total mass of 9, so 9 is a good integer.
Note that 12 is not a good integer.


Sample Input 4

7 251
202 20 5 1 4 2 100

Sample Output 4

48