This page is still under construction.

Parts of this page are still being built. What you see may change.

Explosive Materials

Time limit1sMemory limit128 MB

Summary
Fill each huge truck capacity exactly with unlimited explosive sizes using as few units as possible, or report impossibility.
Level

Hard8 of 10

Topics
Shortest path, Math, Number theory
Solved
No attempts yet

Problem

You have taken a contract to transport explosives. You have nn trucks, and the ii-th truck has capacity xix_i.

For each truck you must plan how to pack it with explosives. Every truck has to be packed exactly full with explosives, because otherwise the materials may be damaged during transport. You have kk types of explosives with distinct sizes, where the ii-th type has size yiy_i, and you can produce as much of each type as you need. Because loading and unloading trucks quickly matters, you want to use as few units of explosive as possible to fill a truck.

For each truck, compute the minimum number of explosive units needed to fill it exactly.

Input

The first line contains two integers nn and kk (1≤n≤10001 \le n \le 1000, 1≤k≤1001 \le k \le 100), the number of trucks and the number of explosive types. Each of the next kk lines contains the size yiy_i of one explosive type (1≤yi<1051 \le y_i < 10^5). Any two types have distinct sizes. Each of the next nn lines contains the capacity xix_i of one truck (1010≤xi≤101710^{10} \le x_i \le 10^{17}).

Output

Print nn lines. On the ii-th line print wiw_i, the minimum number of explosive units needed to fill the ii-th truck exactly, or the single word NIE if it is impossible.

Examples3

  1. Example 1

    Input
    3 2
    10000
    10100
    10000000000
    10000000001
    10000000002
    
    Expected output
    990100
    NIE
    NIE
    
  2. Example 2

    Input
    2 1
    7
    10000000003
    10000000000
    
    Expected output
    1428571429
    NIE
    
  3. Example 3

    Input
    1 2
    2
    5
    10000000001
    
    Expected output
    2000000002