atcoder#ABC136E. [ABC136E] Max GCD

[ABC136E] Max GCD

Score : 500500 points

Problem Statement

We have a sequence of NN integers: A1,A2,,ANA_1, A_2, \cdots, A_N.

You can perform the following operation between 00 and KK times (inclusive):

  • Choose two integers ii and jj such that iji \neq j, each between 11 and NN (inclusive). Add 11 to AiA_i and 1-1 to AjA_j, possibly producing a negative element.

Compute the maximum possible positive integer that divides every element of AA after the operations. Here a positive integer xx divides an integer yy if and only if there exists an integer zz such that y=xzy = xz.

Constraints

  • 2N5002 \leq N \leq 500
  • 1Ai1061 \leq A_i \leq 10^6
  • 0K1090 \leq K \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN KK

A1A_1 A2A_2 \cdots AN1A_{N-1} ANA_{N}

Output

Print the maximum possible positive integer that divides every element of AA after the operations.

2 3
8 20
7

77 will divide every element of AA if, for example, we perform the following operation:

  • Choose i=2,j=1i = 2, j = 1. AA becomes (7,21)(7, 21).

We cannot reach the situation where 88 or greater integer divides every element of AA.

2 10
3 5
8

Consider performing the following five operations:

  • Choose i=2,j=1i = 2, j = 1. AA becomes (2,6)(2, 6).
  • Choose i=2,j=1i = 2, j = 1. AA becomes (1,7)(1, 7).
  • Choose i=2,j=1i = 2, j = 1. AA becomes (0,8)(0, 8).
  • Choose i=2,j=1i = 2, j = 1. AA becomes (1,9)(-1, 9).
  • Choose i=1,j=2i = 1, j = 2. AA becomes (0,8)(0, 8).

Then, 0=8×00 = 8 \times 0 and 8=8×18 = 8 \times 1, so 88 divides every element of AA. We cannot reach the situation where 99 or greater integer divides every element of AA.

4 5
10 1 2 22
7
8 7
1 7 5 6 8 2 6 5
5