N, W = gets.split.map(&:to_i) a = gets.split.map(&:to_i) answer = 0 0.upto(3**N) do |n| bit_str = n.to_s(3).rjust(N, '0') next if bit_str.count('2') > 1 sum = bit_str.chars.each_with_index.inject(0) { |acc, (bit, i)| price = case bit when '0' 0 when '1' a[i] else a[i] / 2 end acc + price } answer += 1 if sum == W end puts answer