← Home
```go
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n, k int
	fmt.Fscan(reader, &n, &k)

	c := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &c[i])
	}

	// dp[j][x] = true means: there exists a subset of coins whose total sum is j,
	// and some sub-subset of that subset sums to x.
	// We want all x such that dp[k][x] is true.

	// State: dp[j][x] means we can select coins summing to j total, with a marked
	// sub-subset summing to x.
	// When we add coin c[i], for each state (j, x):
	// - don't take coin: (j, x) stays
	// - take coin in subset but not in sub-subset: (j + c[i], x)
	// - take coin in subset and in sub-subset: (j + c[i], x + c[i])

	// dp is a 2D boolean array of size (k+1) x (k+1)
	dp := make([][]bool, k+1)
	for i := 0; i <= k; i++ {
		dp[i] = make([]bool, k+1)
	}
	dp[0][0] = true

	for i := 0; i < n; i++ {
		ci := c[i]
		// Iterate in reverse to avoid using the same coin twice
		for j := k; j >= ci; j-- {
			for x := j; x >= 0; x-- {
				if x >= ci && dp[j-ci][x-ci] {
					dp[j][x] = true
				}
				if dp[j-ci][x] {
					dp[j][x] = true
				}
			}
		}
	}

	result := []int{}
	for x := 0; x <= k; x++ {
		if dp[k][x] {
			result = append(result, x)
		}
	}

	fmt.Fprintln(writer, len(result))
	for i, v := range result {
		if i > 0 {
			fmt.Fprint(writer, " ")
		}
		fmt.Fprint(writer, v)
	}
	fmt.Fprintln(writer)
}
```