#K71667. Maximum Fruit from Three Consecutive Trees

    ID: 33583 Type: Default 1000ms 256MiB

Maximum Fruit from Three Consecutive Trees

Maximum Fruit from Three Consecutive Trees

You are given nn trees in a row, where each tree produces a certain amount of fruits. The fruits produced by the ii-th tree is denoted by aia_i with 0ai1040 \leq a_i \leq 10^4, and you have to find the maximum total amount of fruits that can be collected by selecting any three consecutive trees. Note that nn satisfies 3n1053 \leq n \leq 10^5. For example, if n=5n=5 and the fruits array is [4, 2, 3, 7, 1], then the maximum sum is 4+2+3=124+2+3=12. Read the input from standard input (stdin) and output the result to standard output (stdout).

inputFormat

The input consists of two lines. The first line contains an integer nn, the number of trees. The second line contains nn space-separated integers representing the number of fruits produced by each tree.

outputFormat

Output a single integer which is the maximum total amount of fruits that can be collected from any three consecutive trees.## sample

5
4 2 3 7 1
12

</p>