Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/bit-qism-toplamlar

Subsets with sum S

Medium 1000 ms 128 MB 64%
Share

$n$ positive integers $a_{1}, a_{2}, \ldots, a_{n}$ and an integer $S$ are given. Find how many subsets have the sum of their elements equal to exactly $S$. The sum of the empty set is $0$; elements with equal values at different positions are considered different.

Choosing subsets of the numbers whose sum equals the given number

Input

The first line contains two integers: $n$ and $S$. The second line contains $n$ positive integers $a_{i}$ separated by spaces.

Output

One integer — the number of subsets.

Note

$1 \le n \le 16$
$1 \le a_{i} \le 10^{6}$
$0 \le S \le 1.6 * 10^{7}$

Examples

Input #1
4 10
2 3 5 7
Output #1
2
Input #2
3 100
1 2 3
Output #2
0

Sign in to submit a solution

Signing up is free and takes a minute.