#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 *, char);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, ...);
short *malloc(char);
int main() {
  FILE *f = fopen("INP.TXT", "r");
  char n, i;
  short *a, b;
  long k;
  fscanf(f, "%hhd %ld", &n, &k);
  a = malloc(n * sizeof(short));
  for (i = 0; i < n; i++)
    fscanf(f, "%hd", a + i);
  for (i = 0; i < n && k > 0; i++) {
    fscanf(f, "%hd", &b);
    k -= b - a[i];
  }
  fclose(f);
  f = fopen("OUT.TXT", "w");
  fprintf(f, "%hhd\n", (n - i) ? i : -1);
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
lea    0xe9b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe89(%rip),%rsi
lea    -0x11(%rbp),%rdx
lea    -0x30(%rbp),%rcx
mov    $0x0,%al
call   1040 <fscanf@plt>
movsbq -0x11(%rbp),%rax
shl    $0x1,%rax
movsbl %al,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
movb   $0x0,-0x12(%rbp)
movsbl -0x12(%rbp),%eax
movsbl -0x11(%rbp),%ecx
cmp    %ecx,%eax
jge    11e9 <main+0x99>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rdx
movsbl -0x12(%rbp),%eax
cltq
shl    $0x1,%rax
add    %rax,%rdx
lea    0xe3e(%rip),%rsi
mov    $0x0,%al
call   1040 <fscanf@plt>
mov    -0x12(%rbp),%al
add    $0x1,%al
mov    %al,-0x12(%rbp)
jmp    11a9 <main+0x59>
movb   $0x0,-0x12(%rbp)
movsbl -0x12(%rbp),%ecx
movsbl -0x11(%rbp),%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x31(%rbp)
jge    120d <main+0xbd>
cmpq   $0x0,-0x30(%rbp)
setg   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    121d <main+0xcd>
jmp    1261 <main+0x111>
mov    -0x10(%rbp),%rdi
lea    0xdeb(%rip),%rsi
lea    -0x22(%rbp),%rdx
mov    $0x0,%al
call   1040 <fscanf@plt>
movswl -0x22(%rbp),%eax
mov    -0x20(%rbp),%rcx
movsbq -0x12(%rbp),%rdx
movswl (%rcx,%rdx,2),%ecx
sub    %ecx,%eax
movslq %eax,%rcx
mov    -0x30(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x12(%rbp),%al
add    $0x1,%al
mov    %al,-0x12(%rbp)
jmp    11ed <main+0x9d>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xda6(%rip),%rdi
lea    0xda7(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
movsbl -0x11(%rbp),%eax
movsbl -0x12(%rbp),%ecx
sub    %ecx,%eax
cmp    $0x0,%eax
je     12a8 <main+0x158>
movsbl -0x12(%rbp),%eax
mov    %eax,-0x44(%rbp)
jmp    12b5 <main+0x165>
mov    $0xffffffff,%eax
mov    %eax,-0x44(%rbp)
jmp    12b5 <main+0x165>
mov    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%eax
lea    0xd5e(%rip),%rsi
movsbl %al,%edx
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x50,%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    0xe9b(%rip),%rdi
lea    0xe9c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r13
lea    0xe8f(%rip),%rsi
xor    %ebp,%ebp
lea    0xd(%rsp),%rdx
lea    0x10(%rsp),%rcx
mov    %rax,%rdi
xor    %eax,%eax
call   1040 <fscanf@plt>
mov    0xd(%rsp),%bl
lea    (%rbx,%rbx,1),%eax
movsbl %al,%edi
call   1060 <malloc@plt>
test   %bl,%bl
jle    123c <main+0xec>
mov    %rax,%r14
lea    0xe61(%rip),%r15
mov    %rax,%rbx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <fscanf@plt>
add    $0x1,%rbp
movsbq 0xd(%rsp),%rax
add    $0x2,%rbx
cmp    %rax,%rbp
jl     11c0 <main+0x70>
xor    %ebp,%ebp
test   %al,%al
jle    123c <main+0xec>
cmpq   $0x0,0x10(%rsp)
jle    123c <main+0xec>
lea    0xe1b(%rip),%r15
lea    0xe(%rsp),%r12
xor    %ebp,%ebp
nop
mov    %r13,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <fscanf@plt>
movswq 0xe(%rsp),%rcx
movswq (%r14,%rbp,2),%rax
sub    %rcx,%rax
add    0x10(%rsp),%rax
mov    %rax,0x10(%rsp)
add    $0x1,%rbp
movsbq 0xd(%rsp),%rcx
cmp    %rcx,%rbp
jge    123c <main+0xec>
test   %rax,%rax
jg     1200 <main+0xb0>
mov    %r13,%rdi
call   1030 <fclose@plt>
lea    0xdcc(%rip),%rdi
lea    0xdcd(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
cmp    %bpl,0xd(%rsp)
movzbl %bpl,%eax
mov    $0xff,%ecx
cmovne %eax,%ecx
movsbl %cl,%edx
lea    0xdac(%rip),%rsi
mov    %rbx,%rdi
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 = [9 x i8] c"%hhd %ld\00"
@.str.3 = [4 x i8] c"%hd\00"
@.str.4 = [8 x i8] c"OUT.TXT\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [6 x i8] c"%hhd\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8
%4 = alloca i8
%5 = alloca i16*
%6 = alloca i16
%7 = alloca i64
store i32 0, i32* %1
%8 = 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* %8, i32** %2
%9 = load i32*, i32** %2
%10 = call i32 (i32*, i8*, ...) @fscanf(i32* %9, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %3, i64* %7)
%11 = load i8, i8* %3
%12 = sext i8 %11 to i64
%13 = mul i64 %12, 2
%14 = trunc i64 %13 to i8
%15 = call i16* @malloc(i8 signext %14)
store i16* %15, i16** %5
store i8 0, i8* %4
br label %16
16: ; preds = %30, %0
%17 = load i8, i8* %4
%18 = sext i8 %17 to i32
%19 = load i8, i8* %3
%20 = sext i8 %19 to i32
%21 = icmp slt i32 %18, %20
br i1 %21, label %22, label %33
22: ; preds = %16
%23 = load i32*, i32** %2
%24 = load i16*, i16** %5
%25 = load i8, i8* %4
%26 = sext i8 %25 to i32
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i16, i16* %24, i64 %27
%29 = call i32 (i32*, i8*, ...) @fscanf(i32* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i16* %28)
br label %30
30: ; preds = %22
%31 = load i8, i8* %4
%32 = add i8 %31, 1
store i8 %32, i8* %4
br label %16
33: ; preds = %16
store i8 0, i8* %4
br label %34
34: ; preds = %60, %33
%35 = load i8, i8* %4
%36 = sext i8 %35 to i32
%37 = load i8, i8* %3
%38 = sext i8 %37 to i32
%39 = icmp slt i32 %36, %38
br i1 %39, label %40, label %43
40: ; preds = %34
%41 = load i64, i64* %7
%42 = icmp sgt i64 %41, 0
br label %43
43: ; preds = %40, %34
%44 = phi i1 [ false, %34 ], [ %42, %40 ]
br i1 %44, label %45, label %63
45: ; preds = %43
%46 = load i32*, i32** %2
%47 = call i32 (i32*, i8*, ...) @fscanf(i32* %46, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i16* %6)
%48 = load i16, i16* %6
%49 = sext i16 %48 to i32
%50 = load i16*, i16** %5
%51 = load i8, i8* %4
%52 = sext i8 %51 to i64
%53 = getelementptr inbounds i16, i16* %50, i64 %52
%54 = load i16, i16* %53
%55 = sext i16 %54 to i32
%56 = sub nsw i32 %49, %55
%57 = sext i32 %56 to i64
%58 = load i64, i64* %7
%59 = sub nsw i64 %58, %57
store i64 %59, i64* %7
br label %60
60: ; preds = %45
%61 = load i8, i8* %4
%62 = add i8 %61, 1
store i8 %62, i8* %4
br label %34
63: ; preds = %43
%64 = load i32*, i32** %2
%65 = call i32 @fclose(i32* %64)
%66 = 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* %66, i32** %2
%67 = load i32*, i32** %2
%68 = load i8, i8* %3
%69 = sext i8 %68 to i32
%70 = load i8, i8* %4
%71 = sext i8 %70 to i32
%72 = sub nsw i32 %69, %71
%73 = icmp ne i32 %72, 0
br i1 %73, label %74, label %77
74: ; preds = %63
%75 = load i8, i8* %4
%76 = sext i8 %75 to i32
br label %78
77: ; preds = %63
br label %78
78: ; preds = %77, %74
%79 = phi i32 [ %76, %74 ], [ -1, %77 ]
%80 = trunc i32 %79 to i8
%81 = call i32 @fprintf(i32* %67, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8 signext %80)
%82 = load i32*, i32** %2
%83 = call i32 @fclose(i32* %82)
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"INP.TXT\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"%hhd %ld\00"
@.str.3 = [4 x i8] c"%hd\00"
@.str.4 = [8 x i8] c"OUT.TXT\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [6 x i8] c"%hhd\0A\00"
define i32 @main() {
%1 = alloca i8
%2 = alloca i16
%3 = alloca i64
%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 i16* %2 to i8*
%6 = bitcast i64* %3 to i8*
%7 = call i32 (i32*, i8*, ...) @fscanf(i32* %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %1, i64* %3)
%8 = load i8, i8* %1
%9 = shl i8 %8, 1
%10 = call i16* @malloc(i8 signext %9)
%11 = icmp sgt i8 %8, 0
br i1 %11, label %17, label %44
12: ; preds = %17
%13 = icmp sgt i8 %22, 0
%14 = load i64, i64* %3
%15 = icmp sgt i64 %14, 0
%16 = select i1 %13, i1 %15, i1 false
br i1 %16, label %25, label %44
17: ; preds = %0, %17
%18 = phi i64 [ %21, %17 ], [ 0, %0 ]
%19 = getelementptr inbounds i16, i16* %10, i64 %18
%20 = call i32 (i32*, i8*, ...) @fscanf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i16* %19)
%21 = add nuw nsw i64 %18, 1
%22 = load i8, i8* %1
%23 = sext i8 %22 to i64
%24 = icmp slt i64 %21, %23
br i1 %24, label %17, label %12
25: ; preds = %12, %25
%26 = phi i64 [ %36, %25 ], [ 0, %12 ]
%27 = call i32 (i32*, i8*, ...) @fscanf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i16* %2)
%28 = load i16, i16* %2
%29 = sext i16 %28 to i64
%30 = getelementptr inbounds i16, i16* %10, i64 %26
%31 = load i16, i16* %30
%32 = sext i16 %31 to i64
%33 = sub nsw i64 %32, %29
%34 = load i64, i64* %3
%35 = add i64 %33, %34
store i64 %35, i64* %3
%36 = add nuw nsw i64 %26, 1
%37 = load i8, i8* %1
%38 = sext i8 %37 to i64
%39 = icmp slt i64 %36, %38
%40 = icmp sgt i64 %35, 0
%41 = select i1 %39, i1 %40, i1 false
br i1 %41, label %25, label %42
42: ; preds = %25
%43 = trunc i64 %36 to i8
br label %44
44: ; preds = %0, %42, %12
%45 = phi i8 [ 0, %12 ], [ %43, %42 ], [ 0, %0 ]
%46 = call i32 @fclose(i32* %4)
%47 = 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))
%48 = load i8, i8* %1
%49 = icmp eq i8 %48, %45
%50 = select i1 %49, i8 -1, i8 %45
%51 = call i32 @fprintf(i32* %47, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8 signext %50)
%52 = call i32 @fclose(i32* %47)
ret i32 0
}