1.

// Evgeni & Christoph

import java.io.*;
import java.util.*;

public class Wine {
public static void main(String...args)
{
Scanner sc = new Scanner(System.in);
long n;

while((n = sc.nextLong()) != 0)
{
long sum = 0, solution = 0;
for(int i = 0; i < n; i++)
{
sum += sc.nextLong();
solution += Math.abs(sum);
}
System.out.println(solution);

}
}
}