// yuki 929 よくあるボールを移動するやつ
// 2019.12.4 bal4u

#include <stdio.h>

typedef long long ll;

int getchar_unlocked(void);
#define gc() getchar_unlocked()

#define ABS(x) ((x)>=0? (x): -(x))

int in() {   // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

int main()
{
	int s, N;
	ll ans;
	
	N = in();
	ans = 0, s = 0;
	while (N--)	s -= in()-1, ans += ABS(s);
	printf("%lld\n", ans);
	return 0;
}