#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*/ scanf(char *, int *, ...);
int /*<<< orphan*/ solves(int, int *, int);
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  int first = 0, minutes[n - 1];
  for (int i = 0; i < k; i++)
    scanf("%d", minutes + i);
  scanf("%d", &first);
  for (int i = k; i < n - 1; i++)
    scanf("%d", minutes + i);
  solves(first, minutes, n - 1U);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
xor    %eax,%eax
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1040 <scanf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b4 <main+0x94>
mov    -0x30(%rbp),%rsi
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    117d <main+0x5d>
lea    0xe48(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1208 <main+0xe8>
mov    -0x30(%rbp),%rsi
movslq -0x28(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11cc <main+0xac>
mov    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%edx
sub    $0x1,%edx
call   1030 <solves@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xec8(%rip),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
xor    %eax,%eax
call   1040 <scanf@plt>
mov    %rsp,%r12
movl   $0x0,-0x34(%rbp)
mov    -0x30(%rbp),%eax
add    $0xffffffff,%eax
mov    %rsp,%r14
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
cmpl   $0x0,-0x2c(%rbp)
jle    119e <main+0x7e>
lea    0xe8a(%rip),%r15
mov    %r14,%r13
xor    %ebx,%ebx
xchg   %ax,%ax
mov    %r15,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
add    $0x1,%rbx
movslq -0x2c(%rbp),%rax
add    $0x4,%r13
cmp    %rax,%rbx
jl     1180 <main+0x60>
lea    0xe5e(%rip),%rdi
lea    -0x34(%rbp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
movslq -0x2c(%rbp),%r13
mov    -0x30(%rbp),%edx
add    $0xffffffff,%edx
cmp    %edx,%r13d
jge    11f3 <main+0xd3>
lea    (%r14,%r13,4),%rbx
lea    0xe39(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
add    $0x1,%r13
mov    -0x30(%rbp),%edx
add    $0xffffffff,%edx
movslq %edx,%rax
add    $0x4,%rbx
cmp    %rax,%r13
jl     11d0 <main+0xb0>
mov    -0x34(%rbp),%edi
mov    %r14,%rsi
call   1030 <solves@plt>
mov    %r12,%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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