#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
scalar_t__ abs(int);
int /*<<< orphan*/ printf(char *, long long);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int i, t;
  int a[100000];
  long long int sum = 0;
  while (1) {
    scanf("%d", &t);
    if (t == 0)
      break;
    for (i = 0; i < t; i++) {
      scanf("%d", &a[i]);
    }
    for (i = 1; i < t; i++) {
      a[i] += a[i - 1];
      sum += abs(a[i - 1]);
    }
    printf("%lld\n", sum);
    sum = 0;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x61aa0,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x61a98(%rbp)
lea    0xeac(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,-0xc(%rbp)
jne    116c <main+0x3c>
jmp    1232 <main+0x102>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ab <main+0x7b>
movslq -0x8(%rbp),%rax
lea    -0x61a90(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe68(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1173 <main+0x43>
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    120f <main+0xdf>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
cltq
mov    -0x61a90(%rbp,%rax,4),%ecx
movslq -0x8(%rbp),%rax
add    -0x61a90(%rbp,%rax,4),%ecx
mov    %ecx,-0x61a90(%rbp,%rax,4)
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
cltq
mov    -0x61a90(%rbp,%rax,4),%edi
call   1030 <abs@plt>
add    -0x61a98(%rbp),%rax
mov    %rax,-0x61a98(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11b2 <main+0x82>
mov    -0x61a98(%rbp),%rsi
lea    0xde6(%rip),%rdi
call   1040 <printf@plt>
movq   $0x0,-0x61a98(%rbp)
jmp    114d <main+0x1d>
xor    %eax,%eax
add    $0x61aa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x61a98,%rsp
lea    0xeb8(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
je     1200 <main+0xd0>
lea    0x10(%rsp),%r13
lea    0xe96(%rip),%r12
lea    0xe92(%rip),%r14
lea    0xc(%rsp),%r15
jmp    11a0 <main+0x70>
nopl   0x0(%rax,%rax,1)
xor    %ebx,%ebx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %r12,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
je     1200 <main+0xd0>
test   %eax,%eax
jle    1180 <main+0x50>
mov    %r13,%rbx
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
add    $0x1,%rbp
movslq 0xc(%rsp),%rax
add    $0x4,%rbx
cmp    %rax,%rbp
jl     11b0 <main+0x80>
cmp    $0x2,%eax
jl     1180 <main+0x50>
mov    $0x1,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    0xc(%rsp,%rbp,4),%edi
add    %edi,0x10(%rsp,%rbp,4)
call   1030 <abs@plt>
add    %rax,%rbx
add    $0x1,%rbp
movslq 0xc(%rsp),%rax
cmp    %rax,%rbp
jl     11e0 <main+0xb0>
jmp    1182 <main+0x52>
xor    %eax,%eax
add    $0x61a98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [6 x i8] c"%lld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [100000 x i32]
%5 = alloca i64
store i32 0, i32* %1
store i64 0, i64* %5
br label %6
6: ; preds = %0, %51
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%8 = load i32, i32* %3
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %6
br label %54
11: ; preds = %6
store i32 0, i32* %2
br label %12
12: ; preds = %21, %11
%13 = load i32, i32* %2
%14 = load i32, i32* %3
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %24
16: ; preds = %12
%17 = load i32, i32* %2
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [100000 x i32], [100000 x i32]* %4, i64 0, i64 %18
%20 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %19)
br label %21
21: ; preds = %16
%22 = load i32, i32* %2
%23 = add nsw i32 %22, 1
store i32 %23, i32* %2
br label %12
24: ; preds = %12
store i32 1, i32* %2
br label %25
25: ; preds = %48, %24
%26 = load i32, i32* %2
%27 = load i32, i32* %3
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %51
29: ; preds = %25
%30 = load i32, i32* %2
%31 = sub nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [100000 x i32], [100000 x i32]* %4, i64 0, i64 %32
%34 = load i32, i32* %33
%35 = load i32, i32* %2
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [100000 x i32], [100000 x i32]* %4, i64 0, i64 %36
%38 = load i32, i32* %37
%39 = add nsw i32 %38, %34
store i32 %39, i32* %37
%40 = load i32, i32* %2
%41 = sub nsw i32 %40, 1
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [100000 x i32], [100000 x i32]* %4, i64 0, i64 %42
%44 = load i32, i32* %43
%45 = call i64 @abs(i32 %44)
%46 = load i64, i64* %5
%47 = add nsw i64 %46, %45
store i64 %47, i64* %5
br label %48
48: ; preds = %29
%49 = load i32, i32* %2
%50 = add nsw i32 %49, 1
store i32 %50, i32* %2
br label %25
51: ; preds = %25
%52 = load i64, i64* %5
%53 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %52)
store i64 0, i64* %5
br label %6
54: ; preds = %10
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [6 x i8] c"%lld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100000 x i32]
%3 = bitcast i32* %1 to i8*
%4 = bitcast [100000 x i32]* %2 to i8*
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = icmp eq i32 %6, 0
br i1 %7, label %42, label %8
8: ; preds = %0, %36
%9 = phi i32 [ %40, %36 ], [ %6, %0 ]
%10 = icmp sgt i32 %9, 0
br i1 %10, label %13, label %36
11: ; preds = %13
%12 = icmp sgt i32 %18, 1
br i1 %12, label %21, label %36
13: ; preds = %8, %13
%14 = phi i64 [ %17, %13 ], [ 0, %8 ]
%15 = getelementptr inbounds [100000 x i32], [100000 x i32]* %2, i64 0, i64 %14
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %15)
%17 = add nuw nsw i64 %14, 1
%18 = load i32, i32* %1
%19 = sext i32 %18 to i64
%20 = icmp slt i64 %17, %19
br i1 %20, label %13, label %11
21: ; preds = %11, %21
%22 = phi i64 [ %32, %21 ], [ 1, %11 ]
%23 = phi i64 [ %31, %21 ], [ 0, %11 ]
%24 = add nsw i64 %22, -1
%25 = getelementptr inbounds [100000 x i32], [100000 x i32]* %2, i64 0, i64 %24
%26 = load i32, i32* %25
%27 = getelementptr inbounds [100000 x i32], [100000 x i32]* %2, i64 0, i64 %22
%28 = load i32, i32* %27
%29 = add nsw i32 %28, %26
store i32 %29, i32* %27
%30 = call i64 @abs(i32 %26)
%31 = add nsw i64 %30, %23
%32 = add nuw nsw i64 %22, 1
%33 = load i32, i32* %1
%34 = sext i32 %33 to i64
%35 = icmp slt i64 %32, %34
br i1 %35, label %21, label %36
36: ; preds = %21, %8, %11
%37 = phi i64 [ 0, %11 ], [ 0, %8 ], [ %31, %21 ]
%38 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %37)
%39 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%40 = load i32, i32* %1
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %8
42: ; preds = %36, %0
ret i32 0
}