Source Code
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <deque>
#include <set>

using namespace std;

template<typename t>
t gcd(t a,t b)
{
    if(b==0)
    {
        return a;
    }
    return gcd(b,a%b);
}

long long int power(long long int n,long long int p)
{
    long long int x=1;
    for(int i=1;i<=p;i++)
    {
        x*=n;
    }
    return x;
}


int main()
{
    // hi my name is maen
    //speedup;
    string s;
    int ans=0;
    cin>>s;
    int n=s.size();
    for(int i=0;i<n;i++)
    {
        if(s[i]=='1')
        {
            ans++;
        }
        else
        {
            if(0<i&&i<n-1)
            {
                if(s[i-1]=='1'&&s[i+1]=='1')
                {
                    ans++;
                }
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}
Copy
Japanese holidays maenobaid
GNU G++17
5 ms
776 KB
Accepted