Language: C++

#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

int main() {
    int n;
    cin >> n;
    VI a(n);
    int in, diff,sum = 0;
    LL cnt = 0;
    REP(i,0,n) cin >> a[i];
    sum = a[0];
    bool isz = (sum == 0);
    REP(i,1,n) {
        in = a[i];
        dump(i);
        if (sum < 0) {
            if (sum + in < 0) {
                cnt += abs(sum + in) + 1;
                sum = 1;
                dump(cnt);
            } else if (sum + in > 0) {
                sum = sum + in;
            } else {
                ++cnt;
                sum = 1;
            }
        } else if (sum > 0) {
            if (sum + in < 0) {
                sum = sum + in;
            } else if (sum + in > 0) {
                cnt += abs(sum + in) + 1;
                sum = -1;
                dump(cnt);
            } else {
                ++cnt;
                sum = -1;
            }
        } else {
            if (in != 0) {
                isz = false;
                if (in > 0) sum = in - 1;
                else sum = in + 1;
                cnt = 2 * i - 1;
                if (in == 1) {
                    ++sum;
                    ++cnt++;
                }
                if (in == -1) {
                    --sum;
                    ++cnt;
                }
            }
        }
    }
    //cout << cnt << endl;
    LL cnt2 = cnt;
    if (a[0] > 0) sum = -1;
    else if (a[0] < 0) sum = 1;
    else sum = 0;
    cnt = a[0] + 1;
    if (sum == 0) cnt = 0;
    //isz = (sum == 0);
    REP(i,1,n) {
        in = a[i];
        dump(i);
        if (sum < 0) {
            if (sum + in < 0) {
                cnt += abs(sum + in) + 1;
                sum = 1;
                dump(cnt);
            } else if (sum + in > 0) {
                sum = sum + in;
            } else {
                ++cnt;
                sum = 1;
            }
        } else if (sum > 0) {
            if (sum + in < 0) {
                sum = sum + in;
            } else if (sum + in > 0) {
                cnt += abs(sum + in) + 1;
                sum = -1;
                dump(cnt);
            } else {
                ++cnt;
                sum = -1;
            }
        } else {
            if (in != 0) {
                isz = false;
                if (in > 0) sum = - 1;
                else sum = 1;
                cnt = 2 * i - 1 + abs(in) + 2;
            }
        }
    }
    if (sum == 0) cout << 2 * n - 1 << endl;
    else cout << min(cnt, cnt2) << endl;
    
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:98:26: error: lvalue required as increment operand
   98 |                     ++cnt++;
      |                       ~~~^~