Coin change problem
Very easy
Execution time limit is 1 second
Runtime memory usage limit is 128 megabytes
You are working as a cashier at a cheerful fair, and you have coins of different denominations. An unlimited number of coins is available for each denomination, and the value of each denomination is known. Determine the number of ways to pay a given amount using the available coin denominations.
For example, if you have coin denominations with values , and , the amount can be paid in the following ways: and .
Input
The first line contains two integers: the amount and the number of coin denominations . The second line contains integers , representing the values of the coin denominations. All values are distinct.
Output
Print the number of ways to pay the amount .
Examples
Input #1
Answer #1
Input #2
Answer #2
Submissions 1K
Acceptance rate 43%