Curved Mirrors#1882

Curved Mirrors

0.5 seconds
64 megabytes
Medium

With a single shot, the BFG-9000 destroys all monsters on three adjacent balconies. The balconies themselves remain intact, but the monsters perish. The -th balcony is adjacent to the first one. After each shot, the monsters that are still alive deal damage to Leonid (the main character of the novel) — one point of damage each. Another shot follows, and so on, until all monsters are dead. You are required to determine the minimum total damage Leonid might take.

Input

The first line contains an integer — the number of balconies on which the monsters have established a circular defense (3 \leq N \leq 30).

The second line contains integers — the number of monsters on each balcony (at least and at most on each balcony).

Output

Output the minimum possible total damage.

Examples

Example 1

Loading
Loading