Under construction

Still being built. Things may change

Angles of Overlapping Polygons

Time limit1sMemory limit1024 MB

Summary
Given nested convex polygons with non-increasing vertex counts A_i, find the maximum sum of counted angles in a valid figure.
Level

Medium7 of 10

Topics
Geometry, Math, Greedy
Solved
No attempts yet

Problem

You must draw a figure made of NN convex polygons. The figure must satisfy the following three conditions.

  • The ii-th polygon has AiA_i vertices. (1≤i≤N1 \le i \le N)
  • Every vertex of the (i+1)(i+1)-th polygon lies inside or on the boundary of the ii-th polygon. (1≤i<N1 \le i < N)
  • No two or more polygons may share a vertex.

The ii-th polygon has at least as many vertices as the (i+1)(i+1)-th polygon. That is, Ai≥Ai+1A_i \ge A_{i+1} for every integer ii with 1≤i<N1 \le i < N.

The figure below shows a valid and an invalid drawing when A={4,4,3}A=\{ 4, 4, 3 \}.

Valid figureInvalid figure

You want the score of the figure to be as large as possible. The score is the sum of the angles, each less than 180∘180^\circ, formed by the line segments drawn in the figure, counting only those angles that do not fully contain another angle.

For example, ∠DBA\angle DBA and ∠CBD\angle CBD in the figure above are valid. ∠CBA\angle CBA is not valid, because it contains both ∠DBA\angle DBA and ∠CBD\angle CBD.

Find the maximum score that a valid figure can have.

Input

The first line contains the number of polygons NN.

The second line contains NN integers A1,A2,⋯ ,ANA_1, A_2, \cdots, A_N separated by spaces.

Output

Print the maximum score of a valid figure on the first line.

Constraints

  • 1≤N≤1 0001 \leq N \leq 1\,000
  • 3≤Ai≤1003 \leq A_i \leq 100 (1≤i≤N)(1 \leq i \leq N)
  • Ai≥Ai+1A_i \ge A_{i+1} (1≤i<N)(1 \leq i < N)

Examples3

  1. Example 1

    Input
    1
    4
    
    Expected output
    360
    
  2. Example 2

    Input
    2
    4 3
    
    Expected output
    900
    
  3. Example 3

    Input
    3
    4 4 3
    
    Expected output
    1620