eolymp
bolt
Try our new interface for solving problems
Problems

Candies

Candies

The little boy got into fairy land and saw a road along which laid the bags of candy. On each bag is written the number of sweets. The boy can take in each hand, two sacks, lying beside her. What is the greatest number of candies he can take? \InputFile In the only first line specifies the number of bags \textbf{N }(\textbf{4 <= N <= 10000}), then \textbf{N} numbers through the gap - the amount of sweets in each bag (all numbers are nonnegative and not exceed \textbf{1000000}). \OutputFile Display only the required number - the answer to the problem.
Time limit 0.5 seconds
Memory limit 64 MiB
Input example #1
8 3 8 5 2 1 7 8 5
Output example #1
28
Source II этап Всеукраинской олимпиады школьников 2008-2009, г. Бердичев