시간 제한메모리 제한제출정답맞힌 사람정답 비율
0.35 초 1024 MB0000.000%

문제

Being tired of shooting his huge upcoming movie, Deadpool has decided to take a short break and open a restaurant in Canada. Deadpool is also the chef and he can only cook one type of food: chimichangas. For those of you who don't know what chimichangas are (shame on you!), think of a fried burrito.

Deadpool can cook N unique types of chimichangas, each of them having a precise number of calories (Deadpool doesn't make mistakes). All the chimichangas have at most C calories.

The restaurant has become very popular. Today there are Q clients in line and Deadpool wants to impress them.

Each client eats a K-course meal (K dishes), follows a very strict diet and knows exactly how many calories they are supposed to eat. Client i eats exactly meali calories. Each client would like to know in how many ways they can achieve the amount of calories their diet requires by eating exactly K chimichangas (not necessarily of distinct types).

Given the calorie contents of N types of chimichangas (calorie1, calorie2, …, calorieN), as well as the number of courses K, you must answer Q questions, one for every client's calorie requirement.

입력

The input has the format:

line 1:             N K
line 2:             calorie1 calorie2 ... calorieN
line 3:             Q
line 4 ... Q + 3:   meal1
                    meal2
                    ...
                    mealQ

출력

The output must contain Q lines. Each line must contain a single number, the answer to the corresponding question. Because the answer can be big, you are asked to compute it modulo 2999.

제한

  • 1 ≤ caloriei ≤ C for 1 ≤ i ≤ N
  • 0 ≤ meali ≤ W for 1 ≤ i ≤ Q
  • 1 ≤ C × K ≤ 100,000
  • 1 ≤ N ≤ C
  • 0 ≤ W ≤ 1,000,000,000
  • 1 ≤ Q ≤ 200,000
  • Deadpool has an infinite amount of each type of chimichanga.
  • The order in which each client eats matters (e.g. (1 + 2) is different from (2 + 1))
  • No two types of chimichanga have the same number of calories.
  • The answers must be printed modulo 2999.

서브태스크

번호배점제한
120

N ≤ 100, K ≤ 10, W ≤ 2,000 and C ≤ 500

25

K = 2, W ≤ 60,000 and Q ≤ 100

325

C × K ≤ 10,000 and W ≤ 50,000

420

C × K ≤ 30,000

530

none

예제 입력 1

3 4
1 2 5
3
5
4
8

예제 출력 1

4
1
5

힌트

There are 4 ways to eat 5 calories: (1 + 1 + 1 + 2), (1 + 1 + 2 + 1), (1 + 2 + 1 + 1), (2 + 1 + 1 + 1).

There is 1 way to eat 4 calories: (1 + 1 + 1 + 1).

There are 5 ways to eat 8 calories: (1 + 1 + 1 + 5), (1 + 1 + 5 + 1), (1 + 5 + 1 + 1), (5 + 1 + 1 + 1), (2 + 2 + 2 + 2).

채점 및 기타 정보

  • 예제는 채점하지 않는다.