#P7521. [省选联考 2021 B 卷] 取模

[省选联考 2021 B 卷] 取模

Description

Given nn positive integers aia_i, please choose three numbers i,j,ki, j, k (iji \ne j, iki \ne k, jkj \ne k) such that the value of (ai+aj)modak(a_i + a_j) \bmod a_k is maximized.

Input Format

The first line contains an integer nn, indicating the number of integers.
The second line contains nn integers, indicating aia_i.

Output Format

Output one line with one integer, indicating the answer.

6
4 7 7 5 2 2

6

见附件中的 mod/mod2.in。
见附件中的 mod/mod2.ans。

Hint

For 30%30\% of the testdata, n100n \le 100.
For 60%60\% of the testdata, n3000n \le 3000.
For 100%100\% of the testdata, 3n2×1053 \le n \le 2 \times {10}^5, 1ai1081 \le a_i \le {10}^8.

Translated by ChatGPT 5