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

#GL0000118. ƯCLN sau khi cộng (Row GCD)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

ƯCLN sau khi cộng (Row GCD)

Row GCD

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Given two positive integer arrays a1,…,ana_1,\ldots,a_n and b1,…,bmb_1,\ldots,b_m, for each j=1,…,mj=1,\ldots,m find the GCD of a1+bj,a2+bj,…,an+bja_1+b_j,a_2+b_j,\ldots,a_n+b_j. Each query is independent; the array aa is unchanged.

Input

The first line contains n,mn,m; the second contains nn values aia_i; the third contains mm values bjb_j.

Output

Print mm integers; the jj-th is the GCD for bjb_j.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le 20; 1≤m≤201\le m\le 20; 1≤ai≤1 0001\le a_i\le 1\,000; 1≤bj≤1 0001\le b_j\le 1\,000.
  • Subtask 2 (30 points): 1≤n≤5 0001\le n\le 5\,000; 1≤m≤5 0001\le m\le 5\,000; 1≤ai≤1 000 000 0001\le a_i\le 1\,000\,000\,000; 1≤bj≤1 000 000 0001\le b_j\le 1\,000\,000\,000.
  • Subtask 3 (50 points): 1≤n≤200 0001\le n\le 200\,000; 1≤m≤200 0001\le m\le 200\,000; 1≤ai≤1 000 000 000 000 000 0001\le a_i\le 1\,000\,000\,000\,000\,000\,000; 1≤bj≤1 000 000 000 000 000 0001\le b_j\le 1\,000\,000\,000\,000\,000\,000.

Examples

Input

4 4
1 25 121 169
1 2 7 23

Output

2 3 8 24

Explanation

For b1=1b_1=1, the shifted array is 2, 26, 122, 170 and has GCD 2. The remaining queries give 3, 8, and 24.