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

#GL0000133. ƯCLN của tập con (GCD of Subset)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

ƯCLN của tập con (GCD of Subset)

GCD of Subset

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

Given positive integer array A=(a1,…,an)A=(a_1,\ldots,a_n) and 1≤k≤n1\le k\le n, for each position ii, choose exactly kk distinct indices including ii. Maximize the GCD of the selected values and output that optimum for every ii in the original order.

Input

The first line contains n,kn,k; the second contains nn integers aia_i.

Output

Print exactly nn lines; line ii is the maximum GCD attainable with index ii included.

Subtasks

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

Examples

Input

5 2
3 4 6 7 12

Output

3
4
6
1
6

Explanation

Choose (3,6) for index 1 to get 3; (4,12) for index 2 to get 4; (6,12) for index 3 to get 6. For 7 no other element shares a divisor above 1; index 5 can pair 12 with 6 to get 6.