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

#TP0000062. Tập số và phương trình tổng (Sumsets)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Tập số và phương trình tổng (Sumsets)

Sumsets

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

You are given a set SS containing nn pairwise distinct integers. Choose four different elements a,b,c,d∈Sa,b,c,d\in S such that a+b+c=da+b+c=d.

Among all valid choices, find the largest value of dd. If no such choice exists, print exactly no solution. Elements can be negative, zero or positive.

Input

  • The first line contains integer nn: the number of set elements.
  • Each of the next nn lines contains exactly one distinct integer belonging to SS.

Output

Print the maximum possible dd, or exactly no solution in lowercase if no valid four-element choice exists.

Subtasks

  • Subtask 1 (20 points): 4≤n≤104\le n\le 10; −229≤si≤229−1-2^{29}\le s_i\le2^{29}-1 for all ii; every two set elements are distinct.
  • Subtask 2 (30 points): 4≤n≤1204\le n\le 120; −229≤si≤229−1-2^{29}\le s_i\le2^{29}-1 for all ii; every two set elements are distinct.
  • Subtask 3 (50 points): 4≤n≤10004\le n\le 1000; −229≤si≤229−1-2^{29}\le s_i\le2^{29}-1 for all ii; every two set elements are distinct.

Examples

Input

5
2
3
5
7
12

Output

12

Explanation

The set is {2,3,5,7,12}\{2,3,5,7,12\}. Choosing a=2a=2, b=3b=3, c=7c=7 gives a+b+c=2+3+7=12a+b+c=2+3+7=12, and all four elements are distinct. Since 1212 is already the largest set element, no larger dd is possible. Therefore output 12.