output_description: Print the answer.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      s
attempt: #!/usr/bin/python3
  
  import re
  
  
  n = input()
  s = input()
  
  
  sb = re.sub(r"^0+", "", s)
  sb = re.sub(r"0+$", "", sb)
  sb = re.sub(r"00+", "-", sb)
  
  tlist = sb.split("-")
  counts_list = []
  
  for t in tlist:
      counts = []
      tt = t.split("0")
      for ttt in tt:
          counts.append(len(ttt))
      counts_list.append(counts)
  
  ans = 0
  
  for counts in counts_list:
  
      len_counts = len(counts)
      sum_all = sum_decr = sum_one = sum_zero = 0
  
      for i in range(len_counts - 1):
  
          new_sum_all = new_sum_decr = new_sum_one = new_sum_zero = 0
  
          # do nothing
          new_sum_all = max(sum_all, sum_decr, sum_one, sum_zero)
  
          # go to left all
          new_sum_decr = max(new_sum_decr, sum_all + counts[i])
          new_sum_decr = max(new_sum_decr, sum_decr + counts[i] - 1)
          new_sum_decr = max(new_sum_decr, sum_one + 1)
  
          # go to right all - 1
          new_sum_one = max(new_sum_one, sum_all + counts[i + 1] - 1)
          if counts[i] >= 2:
              new_sum_one = max(new_sum_one, sum_decr + counts[i + 1] - 1)
          new_sum_one = max(new_sum_one, sum_one + counts[i + 1] - 1)
  
          # go to right all
          new_sum_zero = max(new_sum_zero, sum_all + counts[i + 1])
          if counts[i] >= 2:
              new_sum_zero = max(new_sum_zero, sum_decr + counts[i + 1])
          new_sum_zero = max(new_sum_zero, sum_one + counts[i + 1])
  
          sum_all = new_sum_all
          sum_decr = new_sum_decr
          sum_one = new_sum_one
          sum_zero = new_sum_zero
  
      ans += max(sum_all, sum_decr, sum_one, sum_zero)
  
  
  print(ans)
  
problem_description: Statement
  
  N cells are arranged in a row. Some of them may contain tokens. You are given
  a string s that consists of `0`s and `1`s. 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?
samples: [{"input": "7\n    1010101", "output": "2\n    \n\nFor example, he can perform two operations in the following way:\n\n  * Perform an operation on the last three cells. Now the string that represents tokens becomes `1010010`.\n  * Perform an operation on the first three cells. Now the string that represents tokens becomes `0100010`.\n\nNote that the choice of operations matters. For example, if he chooses three\ncells in the middle first, he can perform no more operations.\n\n* * *"}, {"input": "50\n    10101000010011011110001001111110000101010111100110", "output": "10"}]