Олимпиадный тренинг

Задача 38877. Greatest Common Divisor


The greatest common divisor of a non-empty collection of natural numbers A is the maximum natural number d such that it is simultaneously a divisor of all numbers in the set A.
Given an array of natural numbers [a1, a2, . . . , an] and number k. It is required to choose a subarray of k consecutive elements [al, al+1, . . . , al+k−1] so that their greatest common divisor is as large as possible, and output this greatest common divisor.

Input
The first input line contains two integers n and k (2 ≤ n ≤ 500 000, 2 ≤ k ≤ n).
The second line contains n natural numbers a1, a2, . . . , an (1 ≤ ai ≤ 1018).

Imprint
Print one natural number — the maximum possible value of the greatest common divisor of the elements of a subarray of length k of the given array.
Examples
# Input Output
1 10 4
2 3 4 8 12 6 12 18 4 3
6