import java.math.*; import java.util.*; import java.io.*; class Main { public static void main(String[] args) { new Main().run(); } void run() { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); long[] B = new long[N]; for (int i = 0; i < N; ++i) { B[i] = sc.nextLong(); } long ans = 0; long a = 0; for (int i = 0; i < N; ++i) { ans += Math.abs(a); a += B[i] - 1; } System.out.println(ans); } void tr(Object...o){ System.out.println(Arrays.deepToString(o)); } }