This page is still under construction.

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

Jumping Machine

Time limit1sMemory limit512 MB

Summary
Given n springs with jump lengths, the machine at (0,0) uses each spring once in any order, moving l up or l right; count the grid cells it can ever land on or pass over.
Level

Hard8 of 10

Topics
Combinatorics, Math, Number theory, Dynamic programming
Solved
No attempts yet

Problem

A young inventor has built a new jumping machine. To test it, he brought it to a testing polygon. The polygon is an infinite square grid.

Initially the machine is in cell (0,0)(0, 0). The machine has nn springs, and the ii-th spring has force lil_i and lets the machine jump lil_i cells up or lil_i cells to the right. So this spring lets the machine go from cell (x,y)(x, y) either to cell (x+li,y)(x + l_i, y) or to cell (x,y+li)(x, y + l_i). After a jump the spring is thrown back and cannot be reused. The machine can use the springs in any order.

During the tests, the cells the machine flies over get stained with machine oil. To avoid cleaning the grid afterwards, the inventor decided to put a protective mat on every cell the machine could possibly fly over.

Now the inventor wonders how many protective mats he needs to bring to the test.

Input

The first line of input contains nn, the number of springs the machine has (1≤n≤1001 \le n \le 100). The second line contains nn integers lil_i, the spring forces (li≥1l_i \ge 1; 1≤l1+l2+⋯+ln≤1061 \le l_1 + l_2 + \dots + l_n \le {10}^6).

Output

Output a single integer: the number of mats the inventor needs to bring.

Hint

All the cells that can get dirty when the machine jumps in the example test are colored orange in the figure below.

Cells that the machine can stain.

Examples1

  1. Example 1

    Input
    2
    4 2
    
    Expected output
    22