This page is still under construction.

Parts of this page are still being built. What you see may change.

Mushrooms on Half a Pizza

Time limit1sMemory limit32 MB

Summary
Given mushroom counts on eight circular pizza slices, find the largest total on any four consecutive slices.
Level

Easy2 of 10

Topics
Brute force, Array
Solved
No attempts yet

Problem

After eating every cookie in the witch's house, Hansel and Gretel ordered a jumbo pizza. It arrived soon after, already cut into eight slices. The two of them split the pizza in half, so each takes a full half circle, meaning four consecutive slices.

Gretel loves mushrooms and wants as many as she can get. The slices carry different numbers of mushrooms, so Gretel asked Hansel to cut the pizza in half in the way that gives her share the most mushrooms.

Given the number of mushrooms on each of the eight slices, find the largest total number of mushrooms Gretel can get. The slices form a circle, so the eighth slice and the first slice are neighbors.

Input

Eight lines follow, each holding one integer SiS_i (0≤Si≤500 \le S_i \le 50, i=1,2,…,8i = 1, 2, \ldots, 8). SiS_i is the number of mushrooms on the ii-th slice, with the slices listed in clockwise order.

Output

Print the largest total number of mushrooms Gretel can get on one line.

Examples4

  1. Example 1

    Input
    5
    2
    1
    4
    5
    1
    2
    3
    
    Expected output
    12
    
  2. Example 2

    Input
    2
    6
    5
    3
    3
    7
    2
    6
    
    Expected output
    19
    
  3. Example 3

    Input
    0
    0
    0
    0
    0
    0
    0
    0
    
    Expected output
    0
  4. Example 4

    Input
    50
    50
    50
    50
    50
    50
    50
    50
    
    Expected output
    200