#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 *, ...);
scalar_t__ satisfyCapacity(int *, int, int);
int scanf(char *, int *, ...);
int main() {
  int numPeople, budget, numHotel, numWeek, priceHotel, capacity[13], index,
      minCost, totalPrice;
  while (scanf("%d %d %d %d", &numPeople, &budget, &numHotel, &numWeek) == 4) {
    minCost = budget + 1;
    while (numHotel > 0) {
      scanf("%d", &priceHotel);
      for (index = 0; index < numWeek; index++)
        scanf("%d", &capacity[index]);
      if (satisfyCapacity(capacity, numWeek, numPeople)) {
        totalPrice = numPeople * priceHotel;
        if (totalPrice < minCost)
          minCost = totalPrice;
      }
      numHotel--;
    }
    if (minCost > budget)
      printf("stay home\n");
    else
      printf("%d\n", minCost);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
lea    -0x10(%rbp),%rcx
lea    -0x14(%rbp),%r8
mov    $0x0,%al
call   1050 <scanf@plt>
cmp    $0x4,%eax
jne    1246 <main+0x116>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
cmpl   $0x0,-0x10(%rbp)
jle    1211 <main+0xe1>
lea    0xe89(%rip),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
movl   $0x0,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11c9 <main+0x99>
movslq -0x54(%rbp),%rax
lea    -0x50(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1192 <main+0x62>
lea    -0x50(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x8(%rbp),%edx
call   1040 <satisfyCapacity@plt>
cmp    $0x0,%rax
je     1203 <main+0xd3>
mov    -0x8(%rbp),%eax
imul   -0x18(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
cmp    -0x58(%rbp),%eax
jge    11fe <main+0xce>
mov    -0x5c(%rbp),%eax
mov    %eax,-0x58(%rbp)
jmp    1203 <main+0xd3>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    116f <main+0x3f>
mov    -0x58(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    1230 <main+0x100>
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1241 <main+0x111>
mov    -0x58(%rbp),%esi
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    113f <main+0xf>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
lea    0xeab(%rip),%rdi
lea    0x18(%rsp),%rsi
lea    0x14(%rsp),%rdx
lea    0xc(%rsp),%rcx
lea    0x10(%rsp),%r8
xor    %eax,%eax
call   1060 <scanf@plt>
cmp    $0x4,%eax
jne    1281 <main+0x141>
lea    0xe89(%rip),%rbx
lea    0x1c(%rsp),%r14
lea    0x20(%rsp),%rbp
jmp    11c7 <main+0x87>
nopl   0x0(%rax)
lea    0xe79(%rip),%rdi
call   1030 <puts@plt>
lea    0xe5d(%rip),%rdi
lea    0x18(%rsp),%rsi
lea    0x14(%rsp),%rdx
lea    0xc(%rsp),%rcx
lea    0x10(%rsp),%r8
xor    %eax,%eax
call   1060 <scanf@plt>
cmp    $0x4,%eax
jne    1281 <main+0x141>
cmpl   $0x0,0xc(%rsp)
jle    1190 <main+0x50>
mov    0x14(%rsp),%r13d
add    $0x1,%r13d
jmp    11f0 <main+0xb0>
nopl   0x0(%rax)
mov    0xc(%rsp),%eax
lea    -0x1(%rax),%ecx
mov    %ecx,0xc(%rsp)
cmp    $0x1,%eax
jle    1260 <main+0x120>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0x10(%rsp),%esi
test   %esi,%esi
jle    122f <main+0xef>
mov    %rbp,%r15
xor    %r12d,%r12d
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
add    $0x1,%r12
movslq 0x10(%rsp),%rsi
add    $0x4,%r15
cmp    %rsi,%r12
jl     1210 <main+0xd0>
mov    0x18(%rsp),%edx
mov    %rbp,%rdi
call   1050 <satisfyCapacity@plt>
test   %rax,%rax
je     11e0 <main+0xa0>
mov    0x1c(%rsp),%eax
imul   0x18(%rsp),%eax
cmp    %r13d,%eax
cmovl  %eax,%r13d
jmp    11e0 <main+0xa0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    0x14(%rsp),%r13d
jg     1190 <main+0x50>
lea    0xd9a(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    119c <main+0x5c>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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