PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000155. Bàn bốn chân từ các chồng tiền xu (Mint)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Bàn bốn chân từ các chồng tiền xu (Mint)

Mint

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

A table has four legs made of stacks of coins. Each leg consists of coins of a single type, and four distinct coin types must be used. All four legs must have exactly the same height. Coin thicknesses and desired heights are positive integers measured in hundredths of a millimetre. There is an unlimited supply of each coin type.

For each desired height hh, determine the greatest feasible common leg height not exceeding hh, and the least feasible height not smaller than hh. You may choose a different set of four coin types for each table. Output 00 as the lower bound if no positive feasible height is at most hh.

Input

The first line contains n,tn,t. The next nn lines contain coin thicknesses cic_i; the next tt lines contain target heights hjh_j.

Output

For each target height, print two integers on one line: the greatest feasible height at most the target and the least feasible height at least the target.

Subtasks

  • Subtask 1 (20 points): 4≤n≤84 \le n \le 8; 1≤t≤31 \le t \le 3; 1≤ci≤501 \le c_i \le 50; 1≤hj≤1051 \le h_j \le 10^5.
  • Subtask 2 (30 points): 4≤n≤254 \le n \le 25; 1≤t≤71 \le t \le 7; 1≤ci≤5001 \le c_i \le 500; 1≤hj≤1061 \le h_j \le 10^6.
  • Subtask 3 (50 points): 4≤n≤504 \le n \le 50; 1≤t≤101 \le t \le 10; 1≤ci≤10001 \le c_i \le 1000; 1≤hj≤1071 \le h_j \le 10^7.

Examples

Input

4 2
50
100
200
400
1000
2000

Output

800 1200
2000 2000

Explanation

There are exactly four types, so each leg uses one of them. Their LCM is 400400. The feasible positive heights are 400,800,1200,…400,800,1200,\ldots. Thus the closest feasible heights around 10001000 are 800800 and 12001200; 20002000 itself is feasible.