cswork / OAOpen practice workspace

MicrosoftOA #11

Calculate Leftover Stacks

Estimated EasyJudge-ready

Topics (AI-labelled)SimulationBits & Math

Process the piles from left to right: every two blocks combine into one block that is added to the pile on the right, and the current pile keeps at most one block. Carrying continues past the end of the original array until no more merges are possible. Find the number of piles that end up with one block.

Input

This site's input: the first line contains n (1..100000), and the second line contains n block counts (0..10⁹).

Output

Output a single integer, the answer.

Example 1

Input:

3
5 3 1

Output:

4

Example 2

Input:

1
0

Output:

0

Example 3

Input:

1
2

Output:

1

Example notes

Example 1: the totals pile by pile are 5, 5, 3, and each keeps 1; at the end carry=1 keeps 1 more, for a total of 4.

Example 2: there are no blocks, so the answer is 0.

Example 3: two blocks combine into one to the right, leaving only 1 pile.

Editorial

Loading solution…