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

#GL0000342. GCD lớn nhất sau các phép chuyển đơn vị (Max GCD)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

GCD lớn nhất sau các phép chuyển đơn vị (Max GCD)

Max GCD

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

You are given NN positive integers A1,A2,…,ANA_1,A_2,\ldots,A_N. You may perform at most KK operations:

  • Choose two distinct positions i≠ji\ne j.
  • Increase AiA_i by 11 and decrease AjA_j by 11.

Values are allowed to become zero or negative. Each operation preserves the total sum.

Find the largest positive integer dd for which all entries can be made divisible by dd using at most KK operations.

Input

The first line contains N,KN,K; the second contains NN integers A1,A2,…,ANA_1,A_2,\ldots,A_N.

Output

Print the maximum achievable positive divisor dd.

Subtasks

  • Subtask 1 (20 points): 2≤N≤82\le N\le 8, 1≤Ai≤301\le A_i\le30, 0≤K≤500\le K\le 50.
  • Subtask 2 (30 points): 2≤N≤1002\le N\le 100, 1≤Ai≤1041\le A_i\le10^4, 0≤K≤1050\le K\le 10^5.
  • Subtask 3 (50 points): 2≤N≤5002\le N\le 500, 1≤Ai≤1061\le A_i\le10^6, 0≤K≤1090\le K\le10^9.

Examples

Example 1

Input

2 3
8 20

Output

7

Explanation

Transfer one unit from the first entry to the second: (8,20)→(7,21)(8,20)\to(7,21). Both entries are divisible by 7, and no greater common divisor is reachable with at most three operations.

Example 2

Input

2 10
3 5

Output

8

Explanation

Transfer three units from the first entry to the second, yielding (0,8)(0,8). Any common divisor must divide the unchanged total 8, so 8 is optimal.