PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#QHD0000073. Những giá trị có thể tạo thành (The Values You Can Make)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Những giá trị có thể tạo thành (The Values You Can Make)

The Values You Can Make

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Pari owns nn coins. Coin ii has positive integer value cic_i. To buy chocolate priced at exactly kk, she must choose a subset of her coins whose total value is exactly kk and hand all chosen coins to Arya. Each physical coin may be used at most once; equal-valued coins in different positions are distinct.

Arya may then select any subset of the coins she received, possibly the empty subset. Determine all integer values xx Arya could form for at least one valid way Pari pays. Formally, a value xx is possible if there exist index sets B⊆A⊆{1,2,…,n}B\subseteq A\subseteq\{1,2,\ldots,n\} satisfying

∑i∈Aci=k,∑i∈Bci=x.\sum_{i\in A}c_i=k,\qquad\sum_{i\in B}c_i=x.

The inner subset BB may be empty, so x=0x=0 is allowed. Arya may select all received coins, so x=kx=k is allowed. Report each feasible value only once. It is not sufficient for xx to be a subset sum of the original coins: its coins must fit inside a valid exact-kk payment. A payment of total kk is guaranteed to exist.

Input

The first line contains n,kn,k. The second line contains exactly nn integers c1,c2,…,cnc_1,c_2,\ldots,c_n.

Output

Print the number qq of feasible values on the first line. Print the qq distinct values xx in ascending order on the second line, separated by spaces.

Subtasks

  • Subtask 1 (20 points): 1≤n≤121\le n\le12; 1≤k≤301\le k\le30; 1≤ci≤5001\le c_i\le500; an exact-kk subset exists.

  • Subtask 2 (30 points): 1≤n≤1001\le n\le100; 1≤k≤2001\le k\le200; 1≤ci≤5001\le c_i\le500; an exact-kk subset exists.

  • Subtask 3 (50 points): 1≤n,k≤5001\le n,k\le500; 1≤ci≤5001\le c_i\le500; an exact-kk subset exists.

Examples

Example 1

Input

6 18
5 6 1 10 12 2

Output

16
0 1 2 3 5 6 7 8 10 11 12 13 15 16 17 18

Explanation

For instance, paying 6+10+2=186+10+2=18 permits amounts 0,2,6,8,10,12,16,180,2,6,8,10,12,16,18. Other exact payments yield more values. Taking the union of all valid inner subset sums produces the 1616 reported amounts.

Example 2

Input

3 50
25 25 50

Output

3
0 25 50

Explanation

Paying with the 5050-coin or with both 2525-coins is valid. Only the latter allows Arya to form 2525. The complete set is {0,25,50}\{0,25,50\}.