Curved Mirrors
In one salvo, the BFG-9000 eliminates monsters on three consecutive balconies. The balconies themselves remain intact, but the monsters are annihilated. (The N-th balcony is adjacent to the first one.) After each salvo, any surviving monsters inflict damage on Leonid, the protagonist, with each monster causing one unit of damage. This process repeats with subsequent salvos until all monsters are defeated. Your task is to determine the minimum damage Leonid can sustain.
Input
The first line contains an integer N, representing the number of balconies where the monsters have established a circular defense (3 ≤ N ≤ 30). The second line contains N integers, each indicating the number of monsters on a balcony (ranging from 1 to 100 per balcony).
Output
Output the minimum number of damage units Leonid can receive.