Codeforces Global Round 2
E
Pavel and Triangles
Codeforces
1900
原题
← DF →
翻译中…

Pavel has several sticks with lengths equal to powers of two.

翻译中…

He has $a_0$ sticks of length $2^0 = 1$, $a_1$ sticks of length $2^1 = 2$, ..., $a_{n-1}$ sticks of length $2^{n-1}$.

翻译中…

Pavel wants to make the maximum possible number of triangles using these sticks. The triangles should have strictly positive area, each stick can be used in at most one triangle.

翻译中…

It is forbidden to break sticks, and each triangle should consist of exactly three sticks.

翻译中…

Find the maximum possible number of triangles.

翻译中…

Input

翻译中…

The first line contains a single integer $n$ ($1 \leq n \leq 300\,000$) — the number of different lengths of sticks.

翻译中…

The second line contains $n$ integers $a_0$, $a_1$, ..., $a_{n-1}$ ($1 \leq a_i \leq 10^9$), where $a_i$ is the number of sticks with the length equal to $2^i$.

翻译中…

Output

翻译中…

Print a single integer — the maximum possible number of non-degenerate triangles that Pavel can make.

翻译中…

Note

翻译中…

In the first example, Pavel can, for example, make this set of triangles (the lengths of the sides of the triangles are listed): $(2^0, 2^4, 2^4)$, $(2^1, 2^3, 2^3)$, $(2^1, 2^2, 2^2)$.

翻译中…

In the second example, Pavel cannot make a single triangle.

翻译中…

In the third example, Pavel can, for example, create this set of triangles (the lengths of the sides of the triangles are listed): $(2^0, 2^0, 2^0)$, $(2^1, 2^1, 2^1)$, $(2^2, 2^2, 2^2)$.

翻译中…

样例

Input #1
5
1 2 2 2 2
Output #1
3
InputCopy OutputCopy
Input #2
3
1 1 1
Output #2
0
InputCopy OutputCopy
Input #3
3
3 3 3
Output #3
3
InputCopy OutputCopy
题目信息
题号
1119E
时间限制
2 s
内存限制
256 MB
标签
暴力
动态规划
FFT
贪心
三分

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