A flower shop has an unlimited quantity of flowers of types, each having respectively petals. A corporate client has made orders at the shop. Each order has the following requirements:
- different bouquets must be made, each containing the same number of flowers (two bouquets are considered different if there is a difference in the types of flowers used);
- Only flowers having at least and at most petals may be used;
- Each bouquet may contain at most one flower of each type.
The florists want to use as few flowers as possible. Help them by writing the program bouquets that determines the minimum number of flowers each bouquet can contain for every order so that the given requirements are satisfied.
Input data
The first line of the standard input contains the positive integers and , representing respectively the number of different types of flowers and the number of orders. The next line contains positive integers , indicating the number of petals for each type of flower. Each of the following lines contains three positive integers , , and , describing each order.
Output data
For each order, print the requested number of flowers on a separate line. If a given order cannot be fulfilled, output for it.
Restrictions
| Subtask | Points | Required subtasks | Other constraints | ||
|---|---|---|---|---|---|
| 0 | 0 | The sample test. | |||
| 1 | 11 | ||||
| 2 | 13 | ||||
| 3 | 15 | ||||
| 4 | 19 | ||||
| 5 | 20 | ||||
| 6 | 5 | ||||
| 7 | 17 |
Example
stdin
7 3
3 4 1 1 6 1 2
2 5 3
4 7 3
1 2 5
stdout
1
-1
2
Explanation
For the first order, the flowers of type , and can be used (with , and petals accordingly). If each bouquet contains one flower, exactly different bouquets can be made.
For the second order, the flowers of type and can be used (with and petals accordingly). Thus, it is not possible to make different bouquets. For the third order, a total of types of flowers can be used. If each bouquet contains flowers, at least different bouquets can be made.