Language: C++

#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <deque>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb emplace_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
void print(vec v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(vecll v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(map<int,int> mp){for(auto e:mp)cout<<e.first<<" "<<e.second<<endl;cout<<endl;}

template<typename T>
struct BIT{
    vector<T> data;

    BIT(int size){
        data.assign(++size,0);
    }
    T sum(int k){
        T ret=0;
        for(++k;k>0;k-=k&-k) ret+=data[k];
        return (ret);
    }
    void add(int k,T x){
        for(++k;k<data.size();k+=k&-k)data[k]+=x;
    }
};
/*
和の方
BIT(size) :長さsizeで初期化
sum(k) 区間[0,k]の和を返す
add(k,x) 要素kにxを加える
*/

template<typename T>
struct RBIT{
    BIT<T> bit0,bit1;
    RBIT(int n){
        bit1=bit0=BIT<T>(n);
    }
    //[l,r]にxを加える
    void add(int l,int r,T x){
        bit0.add(l,-x*(l-1));
        bit1.add(l,x);
        bit0.add(r+1,x*r);
        bit1.add(r+1,-x);
    }
    T sum(int i){
        return bit0.sum(i)+bit1.sum(i)*i;
    }
};
int ans;
void proc(vec x){
    rep(i,(int)x.size()-1){
      if(x[i]>1){
        ans+=2;x[i+1]--;
      else if(i+2==x.size()&&x[i+1]>1)ans+=2;
      else if(x[i+1]>1){ans++;x[i+1]--;}
    }
}
main(){
    int n=in();
    string s;cin>>s;
    vector<int> now={0};
    rep(i,n){
      if(now.size()==1 &&now[0]==0&& s[i]=='0'){
        continue;
      }
      if(s[i]=='0'&&(i==n-1||s[i+1]=='0'){
      proc(now);now=vec();now.pb(0);}
      else if(s[i]='0')now.pb(0);
      else now.back()++;
    }
    proc(now);
         cout<<ans;
}


Compiler output:
a.cc: In function 'void proc(std::vector<int>)':
a.cc:95:7: error: expected '}' before 'else'
   95 |       else if(i+2==x.size()&&x[i+1]>1)ans+=2;
      |       ^~~~
a.cc:93:17: note: to match this '{'
   93 |       if(x[i]>1){
      |                 ^
a.cc: At global scope:
a.cc:99:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   99 | main(){
      | ^~~~
a.cc: In function 'int main()':
a.cc:107:42: error: expected ';' before '{' token
  107 |       if(s[i]=='0'&&(i==n-1||s[i+1]=='0'){
      |                                          ^
      |                                          ;
a.cc:109:7: error: expected primary-expression before 'else'
  109 |       else if(s[i]='0')now.pb(0);
      |       ^~~~
a.cc:108:38: error: expected ')' before 'else'
  108 |       proc(now);now=vec();now.pb(0);}
      |                                      ^
      |                                      )
  109 |       else if(s[i]='0')now.pb(0);
      |       ~~~~                            
a.cc:107:9: note: to match this '('
  107 |       if(s[i]=='0'&&(i==n-1||s[i+1]=='0'){
      |         ^