#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 */
scalar_t__ EOF;
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ scanf(char *, long *, ...);
int main() {
  long int cost, participant, butget, hotel, seat, weak, ara, ans = 15000000,
                                                              x = 0, i, j, k;
  while (scanf("%ld %ld %ld %ld", &participant, &butget, &hotel, &weak) !=
         EOF) {
    i = weak;
    k = butget;
    while (hotel--) {
      scanf("%ld", &cost);
      for (j = 0; j < weak; j++) {
        scanf("%d", &seat);
        if (seat >= participant) {
          x = participant * cost;
          if (x < ans)
            ans = x;
        }
      }
    }
    if (ans < butget)
      printf("%ld\n", ans);
    else
      printf("stay home\n");
    ans = 15000000;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0xe4e1c0,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
lea    0xeba(%rip),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x28(%rbp),%rcx
lea    -0x38(%rbp),%r8
mov    $0x0,%al
call   1040 <scanf@plt>
mov    0x2e84(%rip),%rcx
cmp    (%rcx),%rax
je     1261 <main+0x141>
mov    -0x38(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x28(%rbp)
cmp    $0x0,%rax
je     1221 <main+0x101>
lea    0xe6f(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movq   $0x0,-0x60(%rbp)
mov    -0x60(%rbp),%rax
cmp    -0x38(%rbp),%rax
jge    121c <main+0xfc>
lea    0xe4b(%rip),%rdi
lea    -0x30(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x30(%rbp),%rax
cmp    -0x18(%rbp),%rax
jl     1206 <main+0xe6>
mov    -0x18(%rbp),%rax
imul   -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
cmp    -0x48(%rbp),%rax
jge    1201 <main+0xe1>
mov    -0x50(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    1206 <main+0xe6>
jmp    120b <main+0xeb>
mov    -0x60(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x60(%rbp)
jmp    11b0 <main+0x90>
jmp    117d <main+0x5d>
mov    -0x48(%rbp),%rax
cmp    -0x20(%rbp),%rax
jge    1246 <main+0x126>
mov    -0x48(%rbp),%rsi
lea    0xdd9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1254 <main+0x134>
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0xe4e1c0,-0x48(%rbp)
jmp    113f <main+0x1f>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xebb(%rip),%rdi
lea    0x20(%rsp),%rsi
lea    0x18(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0x8(%rsp),%r8
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0x2e81(%rip),%rcx
cmp    (%rcx),%rax
jne    117d <main+0x4d>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe88(%rip),%r14
lea    0x30(%rsp),%r15
lea    0xe80(%rip),%r12
lea    0x28(%rsp),%r13
jmp    11da <main+0xaa>
nopw   0x0(%rax,%rax,1)
lea    0xe71(%rip),%rdi
call   1030 <puts@plt>
lea    0xe4d(%rip),%rdi
lea    0x20(%rsp),%rsi
lea    0x18(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0x8(%rsp),%r8
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0x2e13(%rip),%rcx
cmp    (%rcx),%rax
je     116c <main+0x3c>
mov    $0xe4e1c0,%esi
subq   $0x1,0x10(%rsp)
jae    1200 <main+0xd0>
cmp    0x18(%rsp),%rsi
jge    11a0 <main+0x70>
lea    0xe1e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11ac <main+0x7c>
xchg   %ax,%ax
mov    $0xe4e1c0,%ebx
jmp    121e <main+0xee>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rsi
subq   $0x1,0x10(%rsp)
mov    %rsi,%rbx
jb     11e7 <main+0xb7>
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
cmpq   $0x0,0x8(%rsp)
jle    1210 <main+0xe0>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0x20(%rsp),%rax
mov    0x30(%rsp),%rsi
imul   %rax,%rsi
cmp    %rbx,%rsi
cmovge %rbx,%rsi
cmp    %rax,0x28(%rsp)
cmovl  %rbx,%rsi
add    $0x1,%rbp
mov    %rsi,%rbx
cmp    0x8(%rsp),%rbp
jl     1240 <main+0x110>
jmp    1213 <main+0xe3>

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

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