Arithmetic Snowman

View as PDF

Submit solution

Points: 7 (partial)
Time limit: 3.0s
Memory limit: 64M

Author:
Problem type

k_53P loves to build snowmen. But his favorite type has to be arithmetic snowmen. An arithmetic snowman consists of 3 snowballs whose sizes, when arranged in a non-decreasing order, form an arithmetic sequence. For example, k_53P can make an arithmetic snowman out of snowballs of sizes 1, 3, and 5.

The size of an arithmetic snowman is the sum of the sizes of the snowballs that it's made of. k_53P has made N snowballs of varying sizes, find the largest arithmetic snowman he can make!

Constraints

Subtask 1[50%]

3 \le N \le 100

1 \le size \le 100

Subtask 2[50%]

3 \le N \le 3000

1 \le size \le 10^5

Input Specification

The first line of input will contain N, the number of snowballs.

The second line of input will contain N space-separated integers, the sizes of the snowballs.

Output Specification

One integer, the size of the largest arithmetic snowman k_53P can build. It is guaranteed that he can build at least one.

Sample Input

7
4 2 8 10 14 3 7

Sample Output

24

Explanation for Sample Output

k_53P will use the snowballs of sizes 2, 8 and 14 to make the snowman.


Comments


  • 0
    DragonCav  commented on Jan. 2, 2016, 10:08 p.m.

    for example when there is only one or two number entered; or there are only a few numbers and they don't form an arithmetic sequence anyhow


    • 0
      cheesecake  commented on Jan. 2, 2016, 10:16 p.m.

      It is guaranteed that he can build at least one, the statement has been updated, sorry for the confusion.


  • 4
    XIAOAGE  commented on Jan. 1, 2016, 1:58 p.m.

    It says:

    k_53P has made N snowballs of varying sizes

    But i think the sizes are repeated in batch #1


    • 3
      cheesecake  commented on Jan. 1, 2016, 1:59 p.m.

      Varying sizes does not imply that all sizes are distinct, sorry for the confusion.