defmodule Main do

  def main do
    [n, s] = IO.gets("") |> String.trim() |> String.split(" ") |> Enum.map(&String.to_integer/1)
    list = IO.gets("") |> String.trim() |> String.split(" ") |> Enum.map(&String.to_integer/1)

    count(list, n, s) |> IO.puts()
  end

  @doc """
  count

  ## Examples

      iex> KnapsackForAllSubsets.count([2, 2, 4], 3, 4)
      6
      iex> KnapsackForAllSubsets.count([9, 9, 9, 9, 9], 5, 8)
      0
      iex> KnapsackForAllSubsets.count([3, 1, 4, 1, 5, 9, 2, 6, 5, 3], 10, 10)
      3296

  """
  def count(list, n, s) do
    1..n
    |> Enum.flat_map(fn cnt ->
      list |> combine(cnt)
    end)
    |> Enum.flat_map(fn as ->
      1..(Enum.count(as)) |> Enum.flat_map(fn k -> combine(as, k) end)
    end)
    |> Enum.map(&Enum.sum/1)
    |> Enum.filter(& &1 == s)
    |> Enum.count()
    |> Kernel.div(998244353)
  end

  @spec combine(any, non_neg_integer) :: any
  def combine(collection, k) when is_integer(k) and k >= 0 do
    list = Enum.to_list(collection)
    list_length = Enum.count(list)

    if k > list_length do
      raise Enum.OutOfBoundsError
    else
      do_combine(list, list_length, k, [], [])
    end
  end

  defp do_combine(_list, _list_length, 0, _pick_acc, _acc), do: [[]]
  # optimization
  defp do_combine(list, _list_length, 1, _pick_acc, _acc), do: list |> Enum.map(&[&1])

  defp do_combine(list, list_length, k, pick_acc, acc) do
    list
    |> Stream.unfold(fn [h | t] -> {{h, t}, t} end)
    |> Enum.take(list_length)
    |> Enum.reduce(acc, fn {x, sublist}, acc ->
      sublist_length = Enum.count(sublist)
      pick_acc_length = Enum.count(pick_acc)

      if k > pick_acc_length + 1 + sublist_length do
        # insufficient elements in sublist to generate new valid combinations
        acc
      else
        new_pick_acc = [x | pick_acc]
        new_pick_acc_length = pick_acc_length + 1

        case new_pick_acc_length do
          ^k -> [new_pick_acc | acc]
          _ -> do_combine(sublist, sublist_length, k, new_pick_acc, acc)
        end
      end
    end)
  end
end
