#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *, ...);
int main() {
  FILE *f = fopen("INP.TXT", "r");
  int n, k, a, i, b = 0, r = 1;
  fscanf(f, "%d %d", &n, &k);
  for (i = 0; i < n; i++) {
    fscanf(f, "%d", &a);
    if (a + b > k) {
      b = 0;
      r++;
    }
    b += a;
  }
  fclose(f);
  f = fopen("OUT.TXT", "w");
  fprintf(f, "%d\n", r);
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    0xeab(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x1,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe8b(%rip),%rsi
lea    -0x14(%rbp),%rdx
lea    -0x18(%rbp),%rcx
mov    $0x0,%al
call   1040 <fscanf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11ed <main+0xad>
mov    -0x10(%rbp),%rdi
lea    0xe61(%rip),%rsi
lea    -0x1c(%rbp),%rdx
mov    $0x0,%al
call   1040 <fscanf@plt>
mov    -0x1c(%rbp),%eax
add    -0x24(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    11d6 <main+0x96>
movl   $0x0,-0x24(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1195 <main+0x55>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe13(%rip),%rdi
lea    0xe14(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%edx
lea    0xdff(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xeab(%rip),%rdi
lea    0xeac(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r12
lea    0xe9f(%rip),%rsi
xor    %r13d,%r13d
lea    0xc(%rsp),%rdx
lea    0x14(%rsp),%rcx
mov    %rax,%rdi
xor    %eax,%eax
call   1040 <fscanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    11e2 <main+0xa2>
mov    $0x1,%ebp
lea    0x10(%rsp),%r15
xor    %ebx,%ebx
jmp    11b3 <main+0x73>
nopw   0x0(%rax,%rax,1)
mov    %dl,%cl
add    %ecx,%ebp
add    %eax,%r14d
add    $0x1,%ebx
mov    %r14d,%r13d
cmp    0xc(%rsp),%ebx
jge    11e7 <main+0xa7>
xor    %r14d,%r14d
mov    %r12,%rdi
lea    0xe4d(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <fscanf@plt>
mov    0x10(%rsp),%eax
lea    (%rax,%r13,1),%edx
xor    %ecx,%ecx
cmp    0x14(%rsp),%edx
setg   %dl
jg     11a0 <main+0x60>
mov    %r13d,%r14d
jmp    11a0 <main+0x60>
mov    $0x1,%ebp
mov    %r12,%rdi
call   1030 <fclose@plt>
lea    0xe1a(%rip),%rdi
lea    0xe1b(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xe0e(%rip),%rsi
mov    %rax,%rdi
mov    %ebp,%edx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [8 x i8] c"INP.TXT\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"%d %d\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [8 x i8] c"OUT.TXT\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = bitcast i32* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %1, i32* %2)
%9 = load i32, i32* %1
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %27
11: ; preds = %0, %11
%12 = phi i32 [ %22, %11 ], [ 1, %0 ]
%13 = phi i32 [ %23, %11 ], [ 0, %0 ]
%14 = phi i32 [ %24, %11 ], [ 0, %0 ]
%15 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%16 = load i32, i32* %3
%17 = add nsw i32 %16, %13
%18 = load i32, i32* %2
%19 = icmp sgt i32 %17, %18
%20 = select i1 %19, i32 0, i32 %13
%21 = zext i1 %19 to i32
%22 = add nuw nsw i32 %12, %21
%23 = add nsw i32 %20, %16
%24 = add nuw nsw i32 %14, 1
%25 = load i32, i32* %1
%26 = icmp slt i32 %24, %25
br i1 %26, label %11, label %27
27: ; preds = %11, %0
%28 = phi i32 [ 1, %0 ], [ %22, %11 ]
%29 = call i32 @fclose(i32* %4)
%30 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%31 = call i32 @fprintf(i32* %30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %28)
%32 = call i32 @fclose(i32* %30)
ret i32 0
}