Messy Kevin VIII
Kevin has locked in and has begun grinding LeetCodes. He has been listening to too much Joe Rogan, and has figured out the optimal amount of caffeine required to achieve maximum productivity.
If Kevin goes under the amount of caffeine, he will not be perfectly productive. If he goes over, he will have a heart attack and die (we don't want that!). Therefore, it is very important that Kevin consumes exactly his optimal amount of caffeine.
To get the optimal amount of caffeine, Kevin must use multiple brands of energy drinks as they have varying amounts of caffeine. Since Shahid won big playing poker, he agrees to pay for however many energy drinks Kevin needs to achieve his caffeine requirements.
Kevin also wants to try multiple flavours of energy drink, so he wants to know how many ways he can drink his optimal amount of caffeine, given the caffeine content of each can of energy drink.
Input
The first line contains an integer
,the total number of energy drink flavours.
The second line contains integers
, the amount of caffeine in each flavour.
The third line contains an integer
, which is Kevin's optimal amount of caffeine.
Output
Return the number of combinations of caffeine concentrations that sum exactly to Kevin's optimal caffeine amount. If it is impossible to make the exact caffeine amount required, return $0$.
Example
Input 1
3
1 2 5
5
Output 1
4
There are four ways to drink mg using the concentrations given:
Input 2
1
2
3
Output 2
0
Kevin cannot drink mg of caffeine using only
mg cans.
Input 3
1
10
10
Output 3
1
Comments