Pari wants to buy an expensive chocolate from Arya. She has n coins, the value of the i-th coin is c_{i}. The price of the chocolate is k, so Pari will take a subset of her coins with sum equal to k and give it to Arya.

Looking at her coins, a question came to her mind: after giving the coins to Arya, what values does Arya can make with them? She is jealous and she doesn't want Arya to make a lot of values. So she wants to know all the values x, such that Arya will be able to make x using some subset of coins with the sum k.

Formally, Pari wants to know the values x such that there exists a subset of coins with the sum k such that some subset of this subset has the sum x, i.e. there is exists some way to pay for the chocolate, such that Arya will be able to make the sum x using these coins.


-----Input-----

The first line contains two integers n and k (1  ≤  n, k  ≤  500) — the number of coins and the price of the chocolate, respectively.

Next line will contain n integers c_1, c_2, ..., c_{n} (1 ≤ c_{i} ≤ 500) — the values of Pari's coins.

It's guaranteed that one can make value k using these coins.


-----Output-----

First line of the output must contain a single integer q— the number of suitable values x. Then print q integers in ascending order — the values that Arya can make for some subset of coins of Pari that pays for the chocolate.


-----Examples-----
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 

Input
3 50
25 25 50

Output
3
0 25 50

Difficulty: competition

Starter code:

Solutions:
#coding gbk
#!usr/bin/ENV
cin =lambda : list(map(int,input().split()))
n, k = cin()
c=list(cin())
dp = [0]*(k+1)
dp[0]=1
for i in c:
    tmp = dp[:]
    for x in range(k,i-1,-1):
        tmp[x] |= dp[x-i]|(dp[x-i]<<i)
    dp = tmp
b = bin(dp[-1])
ans = [i for i in range(k + 1) if b[-i - 1] == '1']
print(len(ans))
print(*ans)


n, k = list(map(int, input().split()))
cs = list(map(int, input().split()))

# table[c][s] has bit ss set if can make subset s and sub-subset ss
# using only the first c coins.
# We only ever need to know table[c-1] to compute table[c].
table = [[0 for _ in range(k+1)] for _ in range(2)]

# Can always make subset 0 and sub-subset 0 using 0 coins.
table[0][0] = 1

for i, c in enumerate(cs,1):
	for s in range(k+1):
		# Include the coin in neither subset nor sub-subset.
		table[i%2][s] |= table[(i-1)%2][s]
		if c <= s:
			# Include the coin in subset but not sub-subset.
			table[i%2][s] |= table[(i-1)%2][s-c]
			# Include the coin in both the subset and sub-subset.
			table[i%2][s] |= (table[(i-1)%2][s-c] << c)

possible = [str(i) for i in range(k+1) if (table[n%2][k] >> i) & 1]
print(len(possible))
print(*possible)


n, k = list(map(int, input().split()))
cs = list(map(int, input().split()))

# table[c][s] has bit ss set if can make subset s and sub-subset ss
# using only the first c coins.
# We only ever need to know table[c-1] to compute table[c].
table = [[0 for _ in range(k+1)] for _ in range(2)]

# Can always make subset 0 and sub-subset 0 using 0 coins.
table[0][0] = 1

for i, c in enumerate(cs,1):
	for s in range(k+1):
		# Include the coin in neither subset nor sub-subset.
		table[i%2][s] |= table[(i-1)%2][s]
		if c <= s:
			# Include the coin in subset but not sub-subset.
			table[i%2][s] |= table[(i-1)%2][s-c]
			# Include the coin in both the subset and sub-subset.
			table[i%2][s] |= (table[(i-1)%2][s-c] << c)

possible = [str(i) for i in range(k+1) if (table[n%2][k] >> i) & 1]
print(len(possible))
print(*possible)




# Made By Mostafa_Khaled


n,m=list(map(int,input().split()))
s=[0]+list(map(int,input().split()))
dp=[[[False for i in range(m+1)] for j in range(m+1)] for k in range(2)]
dp[0][0][0]=True
cur=0
for i in range(1,n+1):
    cur+=1
    cur%=2
    last=(cur+1)%2
    for j in range(m+1):
        for k in range(j+1):
            if j-s[i]>-1 and k-s[i]>-1:
                dp[cur][j][k]=dp[last][j][k] or dp[last][j-s[i]][k] or dp[last][j-s[i]][k-s[i]]
            elif j-s[i]>-1 :
                dp[cur][j][k]=dp[last][j][k] or dp[last][j-s[i]][k]
            elif k-s[i]>-1:
                dp[cur][j][k]=dp[last][j][k] or dp[last][j-s[i]][k-s[i]]
            else:
                dp[cur][j][k]=dp[last][j][k]
                
ans=[]
for i in range(k+1):
    if dp[cur][k][i]:
        ans.append(i)
print(len(ans))
print(*ans)
        



def check(arr, l, s):
    m = []
    for _ in range(l+1) : m.append([1] + [0] * (s))
    m[0][0] = 1
    for i, ei in enumerate(arr, 1):
        for j in range(s+1):
            m[i][j] |= m[i-1][j]
            if j >= ei: 
                m[i][j] |= m[i-1][j-ei]
                m[i][j] |= (m[i-1][j-ei] << ei)
    return [i for i in range(s+1) if (m[-1][s] >> i) & 1]

n, s = map(int, input().split())
l = list(map(int, input().split()))
L = check(l, n, s)
print(len(L))
print(*L, sep=' ')


n, k =map(int, input().split())

dp = []
k += 1
for i in range(2):
    a = []
    for j in range(k):
        a.append([0] * k)
    dp.append(a)
dp[1][0][0]=1

c = list(map(int, input().split()))
c = sorted(c)
for i in range(n):
    for j in range(c[i], k):
        for t in range(j+1):
            if t>=c[i] and dp[1][j-c[i]][t-c[i]] > 0:
                dp[0][j][t] = 1
            if dp[1][j-c[i]][t] > 0:
                dp[0][j][t] = 1
    for j in range(k):
        for t in range(j+1):
            if dp[0][j][t]:
                dp[1][j][t] = 1
    if sum(dp[1][k-1]) == k:
        break
print(sum(dp[1][k-1]))
for i in range(k):
    if dp[1][k-1][i]:
        print(i)

n, k =list(map(int, input().split()))

dp = []
k += 1
for j in range(k):
    dp.append([0] * k)

dp[0][0]=1
c = list(map(int, input().split()))

for i in range(n):
    for j in range(k-1, c[i]-1, -1):
        for t in range(j+1):
            if t>=c[i] and dp[j-c[i]][t-c[i]] > 0:
                dp[j][t] = 1
            if dp[j-c[i]][t] > 0:
                dp[j][t] = 1
            
print(sum(dp[k-1]))
for i in range(k):
    if dp[k-1][i]:
        print(i)


n, k =map(int, input().split())

dp = []
k += 1
for j in range(k):
    dp.append([0] * k)

dp[0][0]=1
c = list(map(int, input().split()))
c = sorted(c)
for i in range(n):
    for j in range(k-1, c[i]-1, -1):
        for t in range(j+1):
            if t>=c[i] and dp[j-c[i]][t-c[i]] > 0:
                dp[j][t] = 1
            if dp[j-c[i]][t] > 0:
                dp[j][t] = 1
    if sum(dp[k-1]) == k:
        break
print(sum(dp[k-1]))
for i in range(k):
    if dp[k-1][i]:
        print(i)

from collections import Counter
import sys
n,k = list(map(int,sys.stdin.readline().split()))
c = list(map(int,sys.stdin.readline().split()))
dp = [0]*(k+1)
dp[0]=1
for i in c:
    tmp = dp[:]
    for j in range(k,i-1,-1):
        tmp[j] |= dp[j-i]|(dp[j-i]<<i)
    dp = tmp
b = bin(dp[-1])
ans = [i for i in range(k + 1) if b[-i - 1] == '1']
sys.stdout.write("{0}\n{1}".format(len(ans),str(ans)[1:-1].replace(",","")))


from collections import Counter
import sys
n,k = list(map(int,sys.stdin.readline().split()))
c = list(map(int,sys.stdin.readline().split()))
dp = [0]*(k+1)
dp[0]=1
for i in c:
    tmp = dp[:]
    for j in range(k,i-1,-1):
        tmp[j] |= dp[j-i]|(dp[j-i]<<i)
    dp = tmp
b = bin(dp[-1])
ans = [i for i in range(k + 1) if b[-i - 1] == '1']
sys.stdout.write("{0}\n{1}".format(len(ans),str(ans)[1:-1].replace(",","")))



cin =lambda : map(int,input().split())
n, k = cin()
c=list(cin())
dp = [0]*(k+1)
dp[0]=1
for i in c:
    tmp = dp[:]
    for x in range(k,i-1,-1):
        tmp[x] |= dp[x-i]|(dp[x-i]<<i)
    dp = tmp
b = bin(dp[-1])
ans = [i for i in range(k + 1) if b[-i - 1] == '1']
print(len(ans))
print(*ans)

cin =lambda : list(map(int,input().split()))
n, k = cin()
c=list(cin())
dp = [0]*(k+1)
dp[0]=1
for i in c:
    tmp = dp[:]
    for x in range(k,i-1,-1):
        tmp[x] |= dp[x-i]|(dp[x-i]<<i)
    dp = tmp
b = bin(dp[-1])
ans = [i for i in range(k + 1) if b[-i - 1] == '1']
print(len(ans))
print(*ans)


import sys
input = sys.stdin.readline

n, k = list(map(int, input().split()))
A = list(map(int, input().split()))

DP = [[False]*(k+2) for _ in range(k+2)]

DP[0][0] = True

for a in sorted(A):
  for i in range(k, a-1, -1):
    for j in range(0, k+1):
      DP[i][j] |= DP[i-a][j]
      if j >= a:
        DP[i][j] |= DP[i-a][j-a]

print(sum(DP[k]))
for i in range(k+1):
  if DP[k][i]:
    print(i)


import sys
input = sys.stdin.readline

n, k = list(map(int, input().split()))
A = list(map(int, input().split()))

#DP = [[False]*(k+2) for _ in range(k+2)]
DP = []
for _ in range(k+2):
  DP.append([False]*(k+2))

DP[0][0] = True

for a in sorted(A):
  for i in range(k, a-1, -1):
    for j in range(0, k+1):
      DP[i][j] |= DP[i-a][j]
      if j >= a:
        DP[i][j] |= DP[i-a][j-a]

print(sum(DP[k]))
for i in range(k+1):
  if DP[k][i]:
    print(i)


import sys
input = sys.stdin.readline

n, k = list(map(int, input().split()))
A = list(map(int, input().split()))

#DP = [[False]*(k+2) for _ in range(k+2)]
DP = []
for _ in range(k+1):
  DP.append([False for _ in range(k+1)])

DP[0][0] = True

for a in sorted(A):
  for i in range(k, a-1, -1):
    for j in range(0, k+1):
      DP[i][j] |= DP[i-a][j]
      if j >= a:
        DP[i][j] |= DP[i-a][j-a]

print(sum(DP[k]))
for i in range(k+1):
  if DP[k][i]:
    print(i)


import sys
input = sys.stdin.readline

n, k = list(map(int, input().split()))
A = list(map(int, input().split()))

DP = [[False]*(k+1) for _ in range(k+1)]

DP[0][0] = True

for a in sorted(A):
  for i in range(k, a-1, -1):
    for j in range(0, k+1):
      DP[i][j] |= DP[i-a][j]
      if j >= a:
        DP[i][j] |= DP[i-a][j-a]

print(sum(DP[k]))
for i in range(k+1):
  if DP[k][i]:
    print(i)


import sys
input = sys.stdin.readline

n, k = map(int, input().split())
A = map(int, input().split())

DP = [[False]*(k+1) for _ in range(k+1)]

DP[0][0] = True

for a in sorted(A):
  for i in range(k, a-1, -1):
    for j in range(0, k+1):
      DP[i][j] |= DP[i-a][j]
      if j >= a:
        DP[i][j] |= DP[i-a][j-a]

A = [i for i in range(k+1) if DP[k][i]]
print(len(A))
print(*A)