SDE Path

Coin Change - Number of Ways

Medium

Coin Change - Number of Ways

Given coin denominations, count the number of ways to make a target amount.

Input format

The first line contains N (≤8) and AMOUNT (≤200). The second line contains N distinct coin denominations.

Output format

Print the count of combinations (coin order doesn't matter) that sum to AMOUNT.

Constraints

  • Values fit in a 64-bit signed integer
  • Trailing whitespace and a trailing newline are ignored by the judge

Read from stdin, write to stdout. Sample cases below show the exact format.

Sample cases

Example 1
Input
7 181
9 37 35 31 1 23 38
Expected output
1473
Example 2
Input
6 84
45 19 48 2 22 32
Expected output
17