Under construction

Still being built. Things may change

Switch

Interview

Time limit1sMemory limit1024 MB

Summary
Choose windows of three consecutive seconds, none overlapping, to double their points, and find the maximum total score.
Level

Medium4 of 10

Topics
Dynamic programming, Array
Solved
No attempts yet

Problem

At second ii, the game gives AiA_i points. The game lasts NN seconds. To earn extra points, you can press a switch at second TT. Pressing it doubles the points earned at seconds TT, T+1T+1, and T+2T+2. After you press the switch at second TT, you can press it again starting from second T+3T+3.

Find the maximum total score you can earn by pressing the switch appropriately while the game runs.

Input

The first line contains the number of scoring seconds NN. (3≤N≤200 000)\left( 3 \leq N \leq 200\,000 \right)

The second line contains the integers AiA_i for each second ii, separated by spaces. (1≤i≤N; ∣Ai∣≤1000)\left( 1 \leq i \leq N;\ |A_i| \leq 1000 \right)

Output

Print the maximum total score you can earn.

Examples4

  1. Example 1

    Input
    3
    -2 0 1
    
    Expected output
    0
    
  2. Example 2

    Input
    4
    1 2 3 4
    
    Expected output
    20
    
  3. Example 3

    Input
    5
    -1 -2 -3 -4 -5
    
    Expected output
    -15
    
  4. Example 4

    Input
    9
    -2 10 2 -7 9 1 -2 -3 4
    
    Expected output
    34