#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 *, int *);
int main(int argc, char const *argv[]) {
  int x, y, z, i = 0, t = 0, a, b, c;
  scanf(" %d\n%d\n%d", &x, &y, &z);
  t = x;
  for (i = 0; i < z; ++i) {
    scanf(" %d %d %d", &a, &b, &c);
    t -= 4 * y + a + b + c;
    if (t <= 0) {
      printf("%d %d\n", i + 1, t);
      return 0;
    }
  }
  printf("%d\n", t);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
lea    0xeb5(%rip),%rdi
lea    -0x14(%rbp),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x1c(%rbp),%rcx
call   1040 <scanf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11e4 <main+0xc4>
lea    0xe8e(%rip),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
lea    -0x30(%rbp),%rcx
call   1040 <scanf@plt>
mov    -0x18(%rbp),%ecx
shl    $0x2,%ecx
add    -0x28(%rbp),%ecx
add    -0x2c(%rbp),%ecx
add    -0x30(%rbp),%ecx
mov    -0x24(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jg     11d1 <main+0xb1>
mov    -0x20(%rbp),%esi
add    $0x1,%esi
mov    -0x24(%rbp),%edx
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11fc <main+0xdc>
jmp    11d6 <main+0xb6>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1169 <main+0x49>
mov    -0x24(%rbp),%esi
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%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    0xecb(%rip),%rdi
lea    0x14(%rsp),%rsi
lea    0x10(%rsp),%rdx
mov    %rsp,%rcx
call   1040 <scanf@plt>
mov    0x14(%rsp),%ebx
cmpl   $0x0,(%rsp)
jle    11a9 <main+0x89>
mov    $0x1,%r14d
lea    0xeac(%rip),%r15
lea    0xc(%rsp),%r12
lea    0x8(%rsp),%r13
lea    0x4(%rsp),%rbp
nopl   (%rax)
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
mov    %rbp,%rcx
call   1040 <scanf@plt>
mov    0x10(%rsp),%eax
mov    0xc(%rsp),%ecx
shl    $0x2,%eax
sub    %eax,%ebx
add    0x8(%rsp),%ecx
add    0x4(%rsp),%ecx
sub    %ecx,%ebx
test   %ebx,%ebx
jle    11bb <main+0x9b>
lea    0x1(%r14),%eax
cmp    (%rsp),%r14d
mov    %eax,%r14d
jl     1170 <main+0x50>
lea    0xe67(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11ce <main+0xae>
lea    0xe52(%rip),%rdi
mov    %r14d,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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