#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

//セグメント木
//全て添字で扱うこと
template<typename T>
struct segment_tree {
  ll n; //vのサイズ
  ll m = 1; //葉の数
  vector<T> v;
  T id_e; //単位元

  //二項演算
  T seg_func(T a, T b) {
    return a + b;
  }

  //初期化関数
  void init(vector<T> a, T b) {
    id_e = b;
    while (m < a.size()) m *= 2;
    n = 2 * m - 1;
    vector<T> w(n);
    v = w;
    for (ll i = 0; i < a.size(); i++) v[m - 1 + i] = a[i];
    for (ll i = a.size(); i < m; i++) v[m - 1 + i] = id_e;
    for (ll i = m - 2; i >= 0; i--) {
      v[i] = seg_func(v[2 * i + 1], v[2 * i + 2]);
    }
  }

  //値の更新
  void change(ll a, T b) {
    a += m - 1;
    v[a] = b;
    while ((a - 1) / 2 != a) {
      a = (a - 1) / 2;
      v[a] = seg_func(v[2 * a + 1], v[2 * a + 2]);
    }
  }

  //区間和用の補助関数
  T subsub(ll a, ll b, ll cur, ll l, ll r) {
    if (a <= l && r <= b) return v[cur];
    if (r < a || b < l) return id_e;
    if (l < r) {
      return seg_func(
        subsub(a, b, 2 * cur + 1, l, (l + r) / 2),
        subsub(a, b, 2 * cur + 2, (l + r) / 2 + 1, r)
      );
    }
  }

  //区間[a, b]の和
  T subsum(ll a, ll b) {
    if (a == b) return v[m - 1 + a];
    T ans = id_e;
    ll cur = 0, l = 0, r = m - 1;
    ans = seg_func(ans, subsub(a, b, cur, l, r));
    return ans;
  }

  /*
  セグ木構築の際に用いたもとの配列 a が，
  a[i] == (集合内に存在する i + 1 の数) ならば，
  x_th_minを用いて O(logN) で集合の要素にランダムアクセスできる
  */
  /*
  ll submin(ll x, ll cur, ll l, ll r, ll flag) {
    if (l == r) return l;
    if (v[cur] == x) flag = 1;
    if (flag == 1) {
      if (v[2 * cur + 2] > 0) {
        return submin(x, 2 * cur + 2, (l + r) / 2 + 1, r, flag);
      }
      else {
        return submin(x, 2 * cur + 1, l, (l + r) / 2, flag);
      }
    }
    else {
      if (v[2 * cur + 1] == 0) {
        return submin(x, 2 * cur + 2, (l + r) / 2 + 1, r, flag);
      }
      if (v[2 * cur + 2] == 0) {
        return submin(x, 2 * cur + 1, l, (l + r) / 2, flag);
      }
      if (v[2 * cur + 1] >= x) {
        return submin(x, 2 * cur + 1, l, (l + r) / 2, flag);
      }
      else {
        return submin(x - v[2 * cur + 1], 2 * cur + 2, (l + r) / 2 + 1, r, flag);
      }
    }
  }

  //x番目に小さい要素を求める
  ll x_th_min(ll x) {
    ll cur = 0, l = 0, r = m - 1, flag = 0;
    return submin(x, cur, l, r, flag);
  }
  */
};

int main() {
        ll n;
        cin >> n;
        vll a(n);
        for (ll i = 0; i < n; i++) cin >> a[i];
        segment_tree<ll> seg1, seg2;
        seg1.init(a, 0);
        seg2.init(a, 0);
        ll ans1 = 0, ans2 = 0;
        for (ll i = 0; i < n; i++) {
                ll x = seg1.subsum(0, i), y = seg2.subsum(0, i);
                if (i == 0) {
                        if (x <= 0) {
                                seg1.change(i, 1);
                                ans1 += 1 - x;
                        }
                        if (y >= 0) {
                                seg2.change(i, -1);
                                ans2 += x + 1;
                        }
                }
                else {
                        ll xx = seg1.subsum(0, i - 1), yy = seg2.subsum(0, i - 1);
                        if (xx > 0 && x >= 0) {
                                seg1.change(i, a[i] - (x + 1));
                                ans1 += x + 1;
                        }
                        else if (xx < 0 && x <= 0) {
                                seg1.change(i, a[i] + (1 - x));
                                ans1 += 1 - x;
                        }
                        if (yy > 0 && y >= 0) {
                                seg2.change(i, a[i] - (y + 1));
                                ans2 += y + 1;
                        }
                        else if (yy < 0 && y <= 0) {
                                seg2.change(i, a[i] + (1 - y));
                                ans2 += 1 - y;
                        }
                }
        }
        cout << min(ans1, ans2) << endl;
}

Measured memory_bytes: 8044