package main import ( "fmt" "reflect" "sort" "strconv" "strings" ) func in(i int, l []int) bool { for _, j := range l { if i == j { return true } } return false } func lin(l []int, L [][]int) bool { for _, i := range L { if reflect.DeepEqual(l, i) { return true } } return false } func conv(l []int) string { s := make([]string, len(l)) for i := range l { l[i]++ s[i] = strconv.Itoa(l[i]) } return strings.Join(s, " ") } func main() { var N, S int fmt.Scan(&N, &S) P := make([]int, N) for i := range P { fmt.Scan(&P[i]) } dp := make([][][]int, S+1) for i := range P { if P[i] > S { continue } dp[P[i]] = append(dp[P[i]], []int{i}) } for p := 0; p <= S; p++ { for j := range dp[p] { for i := range P { if p+P[i] > S { continue } if in(i, dp[p][j]) { continue } tmp := make([]int, len(dp[p][j])) copy(tmp, dp[p][j]) tmp = append(tmp, i) sort.Ints(tmp) if lin(tmp, dp[p+P[i]]) { continue } dp[p+P[i]] = append(dp[p+P[i]], tmp) } } } out := make([]string, len(dp[S])) for i := range dp[S] { out[i] = conv(dp[S][i]) } sort.Strings(out) for _, s := range out { fmt.Println(s) } }