Under construction

Still being built. Things may change

Unequalled Consumption

Time limit1sMemory limit128 MB

Summary
Given up to 5 candy weights, find for each query P the smallest total weight whose number of representations (as an unordered multiset count) is at least P, using binary search over weight combined with counting compositions via generating functions or DP.
Level

Medium7 of 10

Topics
Dynamic programming, Binary search, Math, Combinatorics
Solved
No attempts yet

Problem

The Association of Candy Makers is preparing to launch a new product. The idea is old with a novel twist: it simply sells boxes of candies. But since people are what they consume and everyone wants to be unique these days, the Association wants every candy box to be unique, in the sense that no two boxes contain the same composition of candy types.

The Association can make only a small number nn of different candy types, and though limited in imagination, it is virtually limitless in resources, so it can produce as many of each type as it wants. The candy types have weights (some types may weigh the same), and to simplify pricing the Association wants every candy box to have the same total weight.

With these restrictions, the Association can make only a limited number of boxes. For instance, with three candy types weighing 55, 55, and 1010 grams, 44 different boxes can be made with total weight 1010 grams: two of type 1, or two of type 2, or one of type 3, or one each of types 1 and 2. The Association would like to make at least one box for everyone in the cosmos. Given the number of people PP in the cosmos, find the smallest possible total weight ww such that PP different boxes containing exactly ww grams of candy can be made.

Input

The input contains several data sets (at most 2020). Each data set is given on four lines:

  • The first line contains an integer nn (1≤n≤51 \le n \le 5), the number of candy types.
  • The second line contains nn integers w1,…,wnw_1, \dots, w_n (1≤wi≤101 \le w_i \le 10), the weight in grams of each type.
  • The third line contains an integer qq (1≤q≤101 \le q \le 10), the number of queries.
  • The fourth line contains qq integers P1,…,PqP_1, \dots, P_q (1≤Pj≤10151 \le P_j \le 10^{15}), the queries.

The input ends with a line containing a single 00 in place of nn; that terminating data set must not be processed.

Output

For the ii-th data set, print a line Set i, then one line per query. For query PjP_j, print the smallest positive weight WjW_j (in grams) for which at least PjP_j different boxes of total weight exactly WjW_j grams exist. If there is no such weight, print no candy for you for that query instead. When a weight exists, it is at most 100⋅Pj100 \cdot P_j.

Examples3

  1. Example 1

    Input
    3
    5 5 10
    1
    4
    4
    3 1 4 2
    2
    142 700
    1
    10
    1
    100
    0
    
    Expected output
    Set 1
    10
    Set 2
    23
    42
    Set 3
    no candy for you
    
  2. Example 2

    Input
    1
    7
    2
    1 2
    0
    
    Expected output
    Set 1
    7
    no candy for you
    
  3. Example 3

    Input
    2
    2 3
    5
    1 2 3 6 12
    0
    
    Expected output
    Set 1
    2
    6
    12
    30
    66