#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 */
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n;
  scanf("%d", &n);
  int a[100001] = {0};
  int k = 0;
  for (k = 0; k < n; k++) {
    scanf("%d", &a[k]);
  }
  int i;
  int b = 0;
  int c = 0;
  for (i = 0; i < n; i++) {
    if (a[i] > 0) {
      b = b + a[i];
    } else if (a[i] < 0) {
      if ((b + a[i]) < 0) {
        ++c;
      } else {
        b = b + (a[i]);
      }
    }
  }
  printf("%d\n", c);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x61aa0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb7(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
lea    -0x61a90(%rbp),%rdi
xor    %esi,%esi
mov    $0x61a84,%edx
call   1040 <memset@plt>
movl   $0x0,-0x61a94(%rbp)
movl   $0x0,-0x61a94(%rbp)
mov    -0x61a94(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11bd <main+0x8d>
movslq -0x61a94(%rbp),%rax
lea    -0x61a90(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe5c(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x61a94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x61a94(%rbp)
jmp    1179 <main+0x49>
movl   $0x0,-0x61a9c(%rbp)
movl   $0x0,-0x61aa0(%rbp)
movl   $0x0,-0x61a98(%rbp)
mov    -0x61a98(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12a1 <main+0x171>
movslq -0x61a98(%rbp),%rax
cmpl   $0x0,-0x61a90(%rbp,%rax,4)
jle    121e <main+0xee>
mov    -0x61a9c(%rbp),%eax
movslq -0x61a98(%rbp),%rcx
add    -0x61a90(%rbp,%rcx,4),%eax
mov    %eax,-0x61a9c(%rbp)
jmp    1288 <main+0x158>
movslq -0x61a98(%rbp),%rax
cmpl   $0x0,-0x61a90(%rbp,%rax,4)
jge    1283 <main+0x153>
mov    -0x61a9c(%rbp),%eax
movslq -0x61a98(%rbp),%rcx
add    -0x61a90(%rbp,%rcx,4),%eax
cmp    $0x0,%eax
jge    1264 <main+0x134>
mov    -0x61aa0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x61aa0(%rbp)
jmp    127e <main+0x14e>
mov    -0x61a9c(%rbp),%eax
movslq -0x61a98(%rbp),%rcx
add    -0x61a90(%rbp,%rcx,4),%eax
mov    %eax,-0x61a9c(%rbp)
jmp    1283 <main+0x153>
jmp    1288 <main+0x158>
jmp    128d <main+0x15d>
mov    -0x61a98(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x61a98(%rbp)
jmp    11db <main+0xab>
mov    -0x61aa0(%rbp),%esi
lea    0xd55(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x61aa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x61aa0,%rsp
lea    0xebe(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
lea    0x10(%rsp),%rbx
xor    %ebp,%ebp
mov    $0x61a84,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
cmpl   $0x0,0xc(%rsp)
jle    11d3 <main+0xa3>
xor    %ebp,%ebp
lea    0xe8e(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
add    $0x1,%rbp
movslq 0xc(%rsp),%rax
add    $0x4,%rbx
cmp    %rax,%rbp
jl     1180 <main+0x50>
mov    %eax,%eax
test   %eax,%eax
jle    11d1 <main+0xa1>
xor    %ecx,%ecx
xor    %ebp,%ebp
xor    %edx,%edx
jmp    11bb <main+0x8b>
nopl   0x0(%rax,%rax,1)
add    %esi,%edx
add    $0x1,%rcx
cmp    %rcx,%rax
je     11d3 <main+0xa3>
mov    0x10(%rsp,%rcx,4),%esi
test   %esi,%esi
jg     11b0 <main+0x80>
jns    11b2 <main+0x82>
add    %edx,%esi
cmovns %esi,%edx
shr    $0x1f,%esi
add    %esi,%ebp
jmp    11b2 <main+0x82>
xor    %ebp,%ebp
lea    0xe29(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x61aa0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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