Harry Potter and the Deathly Hallows
Practice
0 (0 votes)
Medium Hard
Medium Hard
Problem
69% Success 112 Attempts 50 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Voldemort's army is marching towards Hogwarts. The army consists of N different types of Death Eaters. Luckily, Harry knows Q spells, each of which will exterminate exactly K Death Eaters from the army. He wants to know the number of ways in which he can select a group of exactly K Death Eaters (of various types) he wishes to exterminate using each spell. Two groups are considered different if count of atleast one type of Death Eater is different in both the groups. We can assume that Death Eaters of same type are similar in all aspects.

Input

First line contains N , the types of Death Eaters. Next line contains N numbers where ith number is the number of Death Eaters in the army of ith type. Next line contain Q, the number of spells. Next Q lines contain a number K, the number of Death Eaters it can exterminate.

Output

Print Q lines with a number each giving the number of ways to select a group of Death Eaters of various types to be exterminated. Print the number mod 10^9 +7.

Constraints

1 <= N <= 10^6

1 <= a[i] <= 1000

1 <= Q <= 1000

1 <= K <= 1000

Note

Print ans mod(10^9 + 7).

Use Fast I/O.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
1 votes
Tags:
CombinatoricsDynamic ProgrammingAlgorithmsApprovedMedium-Hard
Points:50
11 votes
Tags:
Medium-Hard
Points:50
2 votes
Tags:
Counting and ArrangementsDynamic ProgrammingAlgorithmsMedium-Hard