Problem:
Score : 700 points

Problem Statement

N cells are arranged in a row.
Some of them may contain tokens.
You are given a string s that consists of 0s and 1s.
If the i-th character of s is 1, the i-th cell (from left) contains a token.
Otherwise, it doesn't contain a token.

Snuke wants to perform the following operation as many times as possible.
In each operation, he chooses three consecutive cells.
Let's call the cells X, Y, Z from left to right.
In order for the operation to be valid, both X and Z must contain tokens and Y must not contain a token.
Then, he removes these two tokens and puts a new token on Y.

How many operations can he perform if he performs operations in the optimal way?

Constraints

1 \leq N \leq 500,000

|s| = N

Each character in s is either 0 or 1.

Input

Input is given from Standard Input in the following format:

N
s

Output

Print the answer.

Sample Input 1

7
1010101

Sample Output 1

2

For example, he can perform two operations in the following way:

Perform an operation on the last three cells. Now the string that represents tokens becomes 1010010.

Perform an operation on the first three cells. Now the string that represents tokens becomes 0100010.

Note that the choice of operations matters.
For example, if he chooses three cells in the middle first, he can perform no more operations.

Sample Input 2

50
10101000010011011110001001111110000101010111100110

Sample Output 2

10

Solution in Pascal (FPC 2.6.2) (judge verdict: Wrong Answer)

 Uses Math;


  const MAX_N = 500000 + 120;
  
  var S : AnsiString;
     N : LongInt;
     ans : Int64;
 
 
 var dp : array [ 0 .. MAX_N , 1 .. 2 ] of LongInt;
     size : array [ 1 .. MAX_N + 12 ] of LongInt;
 
 procedure Solve ( l , R : LongInt ) ;
   var i : LongInt;
       x , cnt : LongInt;
 begin
  if ( L + 2 > R ) then exit();
  
  for i := 1 to R - L + 10 do
  begin
    dp[i][1] := 0;
    dp[i][2] := 0;
    size[i] := 0;
  end;
  
  cnt := 0;
  x := 0;
  
  
  if ( S[R] = '0' ) then halt(1);
  
  for i := L to R do
  begin
    if ( s[i] = '1' ) then
    begin
      cnt += 1;
    end
    else
    begin
      inc ( x ) ;
      size[x] := cnt - 1;
      cnt := 0;
    end;
  end;
  size[x+1] := cnt - 1;
  
  
  
  
  dp[0][1] := 0;
  dp[0][2] := 0;
  
  dp[1][1] := size[1] + 1;
  if ( X <> 1 ) then
    dp[1][2] := 1 + (size[2] - 1)
  else
    dp[1][2] := 1 + (size[2]);
  
  for i := 2 to X do
  begin
    
    if ( size[i] <> 0 ) then // not 10101
    begin
      dp[i][1] := max ( dp[i-1][1] + (size[i] - 1) + 1 , dp[i-1][2] + 1 ); 
      if ( i = X ) then
        dp[i][2] := max ( dp[i-1][1] , dp[i-1][2] ) + size[i+1] + 1
      else
        dp[i][2] := max ( dp[i-1][1] , dp[i-1][2] ) + size[i+1] - 1 + 1;
    end
    else
    begin
      dp[i][1] := max ( max ( dp[i-1][1] , dp[i-1][2] ) , max(dp[i-2][1] , dp[i-2][2] ) + 1 );
      if ( I = X ) then
        dp[i][2] := max ( max ( dp[i-1][1] , dp[i-1][2] ) , max(dp[i-2][1] , dp[i-2][2] ) + size[x+1] + 1 )
      else
        dp[i][2] := max ( max ( dp[i-1][1] , dp[i-1][2] ) , max(dp[i-2][1] , dp[i-2][2] ) + size[x+1] - 1 + 1 );
    end;
    dp[i][1] := max ( dp[i][1] , dp[i][2] );
  end;
  
  
  
  ans += max ( dp[x][1] , dp[x][2] );
  
 end;
 
 var last : LongINt;
 
 var i : LongInt;
 
begin
  ans := 0;
  
  readLn ( N ) ; 
  readLn ( S ) ;
  
  last := 0;
  
  for i := 1 to N do
  begin
    if ( S[i] = '0' ) and ( S[i+1] = '0' ) then
    begin
      Solve ( last + 1 , i - 1 );
      last := i + 1;
    end;
  end;
  
  if ( S[n] = '0' ) then
    Solve ( last + 1 , n-1 )
  else
    Solve ( last + 1 , n );
    
  writeLn ( ans );
  
  
end.