// Arup Guha
// 2/5/2024
// Solution for cases 1-10 to 
// 2024 January USACO Bronze Problem: Balancing Bacteria
// Note: This is O(n^2)

import java.util.*;

public class bacteria_slow {

	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		int n = stdin.nextInt();
		long[] vals = new long[n];
		
		// Read in the values.
		for (int i=0; i<n; i++)
			vals[i] = stdin.nextLong();
			
		long res = 0;

		// Change from the left side to the right.
		for (int i=0; i<n; i++) {
		
			// # of sprays to equal this out.
			res += Math.abs(vals[i]);
			long add = -vals[i];
			
			// Spray accordingly.
			for (int j=i, k=1; j<n; j++,k++)
				vals[j] += (add*k);
		}
	
		// Ta da!
		System.out.println(res);
	}
}