Under construction

Still being built. Things may change

Glass Bead

Interview

Time limit1sMemory limit1024 MB

Summary
Given a 0/1 string of length N, find the maximum number of beads in the pyramid, where each bead needs the two beads below it.
Level

Medium4 of 10

Topics
Array, Math
Solved
No attempts yet

Problem

It looks like a clear glass bead

But it will not break so easily

I love you, so you will not change

I will shine on you forever

You want to build a structure that does not break, using glass beads.

The structure is built by placing glass beads on the points (x,y)(x,y) of the pyramid grid below. (x,yx, y are integers greater than or equal to 00)

To keep the structure from breaking at every point with y>0y>0, it must satisfy the following condition.

  • A glass bead can be at (x,y)(x,y) only if there are glass beads at both (x,y−1)(x,y-1) and (x+1,y−1)(x+1,y-1).

The information for the row y=0y=0 of the structure is given. Place glass beads at points with y>0y>0 as you see fit. Find the maximum number of glass beads the resulting structure can have.

Input

The first line contains the range NN.

The second line contains the information for the row y=0y=0 of the structure as a string of length NN. If the ii-th character is 1, there is a glass bead at (i−1,0)(i-1,0). Otherwise, there is no glass bead there. (1≤i≤N1\leq i\leq N)

There are no glass beads at (x,0)(x,0) outside the range (x≥Nx\geq N).

Output

Print the maximum number of glass beads in the structure on the first line.

Constraints

1≤N≤2000001\leq N\leq 200000

Hint

The answer can exceed the range of C++ int, so using the long long type is recommended.

Examples1

  1. Example 1

    Input
    8
    11011101
    
    Expected output
    10