Under construction

Still being built. Things may change

Light ray polygon

Interview

Time limit1sMemory limit1024 MB

Summary
Given the angles of incidence at mirrors A_1 to A_n of a convex polygon, the task is to find the angle at the laser pointer A_0.
Level

Easy3 of 10

Topics
Math, Geometry
Solved
No attempts yet

Problem

Chang-yeon drew a picture with light rays by placing nn mirrors and a very small laser pointer on a plane.

An example of a picture drawn with light rays

The finished drawing forms a convex polygon A_0A_1⋯A_nA\_0A\_1\cdots A\_n. A_0A\_0 is the point where the laser pointer is located. The ray reflects off the mirrors at A_1,A_2,…,A_nA\_1,A\_2,\ldots ,A\_n in order and returns to A_0A\_0, where the laser pointer blocks it so it goes no further.

A ray reflecting off mirrors as it travels

The ray moves as follows. For convenience, let A_n+1=A_0A\_{n+1}=A\_0.

  • The ray travels in a straight line from A_i−1A\_{i-1} toward A_iA\_i, reflects at A_iA\_i, and then travels in a straight line toward A_i+1A\_{i+1}.
  • The angle of incidence θ_i\theta\_i at A_iA\_i is ∠A_i−1A_iA_i+12\displaystyle \frac{\angle A\_{i-1}A\_iA\_{i+1}}{2}, as shown in the figure.

Given the angles of incidence θ_1,θ_2,…,θ_n\theta\_1,\theta\_2,\ldots ,\theta\_n measured at the moment of reflection at each point A_1,A_2,…,A_nA\_1,A\_2,\ldots ,A\_n, find ∠A_nA_0A_1\angle A\_nA\_0A\_1 in the figure. All angles in the problem use degrees, where a full turn is 360∘360^\circ.

Input

The first line contains an integer nn.

The second line contains nn integers θ_1,θ_2,…,θ_n\theta\_1,\theta\_2,\ldots ,\theta\_n separated by spaces.

Output

Print an integer equal to the size of ∠A_nA_0A_1\angle A\_nA\_0A\_1.

Constraints

  • 2≤n≤502\le n\le 50.
  • 1≤θ_i≤891\le\theta\_i\le 89.
  • All interior angles of the convex polygon drawn on the plane are integers, and each is guaranteed to be at least 1∘1^\circ and at most 179∘179^\circ.

Examples1

  1. Example 1

    Input
    5
    54 63 65 54 61
    
    Expected output
    126