Good Bye 2016
D
New Year and Fireworks
Codeforces
1900
原题
← CE →
翻译中…

One tradition of welcoming the New Year is launching fireworks into the sky. Usually a launched firework flies vertically upward for some period of time, then explodes, splitting into several parts flying in different directions. Sometimes those parts also explode after some period of time, splitting into even more parts, and so on.

翻译中…

Limak, who lives in an infinite grid, has a single firework. The behaviour of the firework is described with a recursion depth $*n*$ and a duration for each level of recursion $*t*_{1}, *t*_{2}, ..., *t*_{*n*}$. Once Limak launches the firework in some cell, the firework starts moving upward. After covering $*t*_{1}$ cells (including the starting cell), it explodes and splits into two parts, each moving in the direction changed by $45$ degrees (see the pictures below for clarification). So, one part moves in the top-left direction, while the other one moves in the top-right direction. Each part explodes again after covering $*t*_{2}$ cells, splitting into two parts moving in directions again changed by $45$ degrees. The process continues till the $*n*$-th level of recursion, when all $2^{*n* - 1}$ existing parts explode and disappear without creating new parts. After a few levels of recursion, it's possible that some parts will be at the same place and at the same time — it is allowed and such parts do not crash.

翻译中…

Before launching the firework, Limak must make sure that nobody stands in cells which will be visited at least once by the firework. Can you count the number of those cells?

翻译中…

Input

翻译中…

The first line of the input contains a single integer $*n*$ ($1 ≤ *n* ≤ 30$) — the total depth of the recursion.

翻译中…

The second line contains $*n*$ integers $*t*_{1}, *t*_{2}, ..., *t*_{*n*}$ ($1 ≤ *t*_{*i*} ≤ 5$). On the $*i*$-th level each of $2^{*i* - 1}$ parts will cover $*t*_{*i*}$ cells before exploding.

翻译中…

Output

翻译中…

Print one integer, denoting the number of cells which will be visited at least once by any part of the firework.

翻译中…

Note

翻译中…

For the first sample, the drawings below show the situation after each level of recursion. Limak launched the firework from the bottom-most red cell. It covered $*t*_{1} = 4$ cells (marked red), exploded and divided into two parts (their further movement is marked green). All explosions are marked with an 'X' character. On the last drawing, there are $4$ red, $4$ green, $8$ orange and $23$ pink cells. So, the total number of visited cells is $4 + 4 + 8 + 23 = 39$.

翻译中…

image

翻译中…

For the second sample, the drawings below show the situation after levels $4$, $5$ and $6$. The middle drawing shows directions of all parts that will move in the next level.

翻译中…

image

翻译中…

样例

Input #1
4
4 2 2 3
Output #1
39
InputCopy OutputCopy
Input #2
6
1 1 1 1 1 3
Output #2
85
InputCopy OutputCopy
Input #3
1
3
Output #3
3
InputCopy OutputCopy
题目信息
题号
750D
所属比赛
时间限制
2.5 s
内存限制
256 MB
标签
暴力
数据结构
DFS 及类似
动态规划
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。