#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 main() {
  int n;
  scanf("%d", &n);
  int p_tea[n];
  for (int i = 0; i < n; i++)
    scanf("%d", p_tea + i);
  int m;
  scanf("%d", &m);
  int p_top[m];
  for (int i = 0; i < m; i++)
    scanf("%d", p_top + i);
  int cheapest = 99999;
  for (int i = 0; i < n; i++) {
    int k;
    scanf("%d", &k);
    for (int j = 0; j < k; j++) {
      int tmp;
      scanf("%d", &tmp);
      int curr = p_tea[i] + p_top[tmp - 1];
      if (curr < cheapest)
        cheapest = curr;
    }
  }
  int money;
  scanf("%d", &money);
  int cups = money / cheapest;
  printf("%d\n", cups > 0 ? cups - 1 : 0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11a2 <main+0x82>
mov    -0x58(%rbp),%rsi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe71(%rip),%rdi
call   1040 <scanf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    116d <main+0x4d>
lea    0xe57(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x20(%rbp),%eax
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x60(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    120e <main+0xee>
mov    -0x60(%rbp),%rsi
movslq -0x2c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe05(%rip),%rdi
call   1040 <scanf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11d9 <main+0xb9>
movl   $0x1869f,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12b1 <main+0x191>
lea    0xdd1(%rip),%rdi
lea    -0x38(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x38(%rbp),%eax
jge    129e <main+0x17e>
lea    0xdae(%rip),%rdi
lea    -0x40(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x60(%rbp),%rcx
mov    -0x58(%rbp),%rax
movslq -0x34(%rbp),%rdx
mov    (%rax,%rdx,4),%eax
mov    -0x40(%rbp),%edx
sub    $0x1,%edx
movslq %edx,%rdx
add    (%rcx,%rdx,4),%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x30(%rbp),%eax
jge    128b <main+0x16b>
mov    -0x44(%rbp),%eax
mov    %eax,-0x30(%rbp)
jmp    1290 <main+0x170>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    123f <main+0x11f>
jmp    12a3 <main+0x183>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    121c <main+0xfc>
lea    0xd48(%rip),%rdi
lea    -0x48(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x48(%rbp),%eax
cltd
idivl  -0x30(%rbp)
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
jle    12e3 <main+0x1c3>
mov    -0x4c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    12ed <main+0x1cd>
xor    %eax,%eax
mov    %eax,-0x64(%rbp)
jmp    12ed <main+0x1cd>
mov    -0x64(%rbp),%esi
lea    0xd0c(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x10(%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    $0x38,%rsp
lea    0xec8(%rip),%rdi
lea    -0x2c(%rbp),%rsi
call   1040 <scanf@plt>
mov    %rsp,-0x48(%rbp)
mov    -0x2c(%rbp),%eax
mov    %rsp,%r13
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
cmpl   $0x0,-0x2c(%rbp)
jle    118c <main+0x6c>
xor    %r15d,%r15d
lea    0xe93(%rip),%r14
mov    %r13,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <scanf@plt>
add    $0x1,%r15
movslq -0x2c(%rbp),%rax
add    $0x4,%rbx
cmp    %rax,%r15
jl     1170 <main+0x50>
lea    0xe6d(%rip),%rdi
lea    -0x34(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x34(%rbp),%eax
mov    %rsp,%rdx
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rdx
mov    %rdx,%rbx
mov    %rdx,%rsp
test   %eax,%eax
jle    11ec <main+0xcc>
xor    %r12d,%r12d
lea    0xe3b(%rip),%r14
mov    %rbx,%r15
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <scanf@plt>
add    $0x1,%r12
movslq -0x34(%rbp),%rax
add    $0x4,%r15
cmp    %rax,%r12
jl     11d0 <main+0xb0>
cmpl   $0x0,-0x2c(%rbp)
jle    12a0 <main+0x180>
mov    %r13,-0x58(%rbp)
mov    $0x1869f,%r15d
xor    %ecx,%ecx
lea    0xdf7(%rip),%rdi
lea    -0x38(%rbp),%rdx
mov    %rbx,%r12
mov    %rbx,-0x50(%rbp)
jmp    123d <main+0x11d>
cs nopw 0x0(%rax,%rax,1)
mov    %r15d,%r13d
mov    -0x40(%rbp),%rcx
mov    %r14,%rdi
mov    %rbx,%rdx
add    $0x1,%rcx
movslq -0x2c(%rbp),%rax
mov    %r13d,%r15d
cmp    %rax,%rcx
jge    12a6 <main+0x186>
mov    %rdx,%rbx
mov    %rcx,-0x40(%rbp)
mov    %rdi,%r14
lea    -0x30(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0x30(%rbp)
jle    1220 <main+0x100>
xor    %r12d,%r12d
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <scanf@plt>
mov    %rbx,%rdx
mov    %r14,%rdi
mov    -0x40(%rbp),%rcx
movslq -0x38(%rbp),%rax
mov    -0x50(%rbp),%rsi
mov    -0x4(%rsi,%rax,4),%r13d
mov    -0x58(%rbp),%rax
add    (%rax,%rcx,4),%r13d
cmp    %r15d,%r13d
cmovge %r15d,%r13d
add    $0x1,%r12d
mov    %r13d,%r15d
cmp    -0x30(%rbp),%r12d
jl     1260 <main+0x140>
jmp    122d <main+0x10d>
mov    $0x1869f,%r13d
lea    0xd53(%rip),%rdi
lea    -0x30(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x30(%rbp),%eax
cltd
idiv   %r13d
lea    -0x1(%rax),%esi
xor    %ecx,%ecx
test   %eax,%eax
cmovle %ecx,%esi
lea    0xd35(%rip),%rdi
call   1030 <printf@plt>
mov    -0x48(%rbp),%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 = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i32 0, i32* %1
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%18 = load i32, i32* %2
%19 = zext i32 %18 to i64
%20 = call i8* @llvm.stacksave()
store i8* %20, i8** %3
%21 = alloca i32, i64 %19
store i64 %19, i64* %4
store i32 0, i32* %5
br label %22
22: ; preds = %31, %0
%23 = load i32, i32* %5
%24 = load i32, i32* %2
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %34
26: ; preds = %22
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %21, i64 %28
%30 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %29)
br label %31
31: ; preds = %26
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
store i32 %33, i32* %5
br label %22
34: ; preds = %22
%35 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%36 = load i32, i32* %6
%37 = zext i32 %36 to i64
%38 = alloca i32, i64 %37
store i64 %37, i64* %7
store i32 0, i32* %8
br label %39
39: ; preds = %48, %34
%40 = load i32, i32* %8
%41 = load i32, i32* %6
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %51
43: ; preds = %39
%44 = load i32, i32* %8
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* %38, i64 %45
%47 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %46)
br label %48
48: ; preds = %43
%49 = load i32, i32* %8
%50 = add nsw i32 %49, 1
store i32 %50, i32* %8
br label %39
51: ; preds = %39
store i32 99999, i32* %9
store i32 0, i32* %10
br label %52
52: ; preds = %84, %51
%53 = load i32, i32* %10
%54 = load i32, i32* %2
%55 = icmp slt i32 %53, %54
br i1 %55, label %56, label %87
56: ; preds = %52
%57 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %11)
store i32 0, i32* %12
br label %58
58: ; preds = %80, %56
%59 = load i32, i32* %12
%60 = load i32, i32* %11
%61 = icmp slt i32 %59, %60
br i1 %61, label %62, label %83
62: ; preds = %58
%63 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %13)
%64 = load i32, i32* %10
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i32, i32* %21, i64 %65
%67 = load i32, i32* %66
%68 = load i32, i32* %13
%69 = sub nsw i32 %68, 1
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i32, i32* %38, i64 %70
%72 = load i32, i32* %71
%73 = add nsw i32 %67, %72
store i32 %73, i32* %14
%74 = load i32, i32* %14
%75 = load i32, i32* %9
%76 = icmp slt i32 %74, %75
br i1 %76, label %77, label %79
77: ; preds = %62
%78 = load i32, i32* %14
store i32 %78, i32* %9
br label %79
79: ; preds = %77, %62
br label %80
80: ; preds = %79
%81 = load i32, i32* %12
%82 = add nsw i32 %81, 1
store i32 %82, i32* %12
br label %58
83: ; preds = %58
br label %84
84: ; preds = %83
%85 = load i32, i32* %10
%86 = add nsw i32 %85, 1
store i32 %86, i32* %10
br label %52
87: ; preds = %52
%88 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %15)
%89 = load i32, i32* %15
%90 = load i32, i32* %9
%91 = sdiv i32 %89, %90
store i32 %91, i32* %16
%92 = load i32, i32* %16
%93 = icmp sgt i32 %92, 0
br i1 %93, label %94, label %97
94: ; preds = %87
%95 = load i32, i32* %16
%96 = sub nsw i32 %95, 1
br label %98
97: ; preds = %87
br label %98
98: ; preds = %97, %94
%99 = phi i32 [ %96, %94 ], [ 0, %97 ]
%100 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %99)
store i32 0, i32* %1
%101 = load i8*, i8** %3
%102 = load i32, i32* %1
ret i32 %102
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [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 = bitcast i32* %1 to i8*
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%8 = load i32, i32* %1
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
%11 = alloca i32, i64 %9
%12 = load i32, i32* %1
%13 = icmp sgt i32 %12, 0
br i1 %13, label %21, label %14
14: ; preds = %21, %0
%15 = bitcast i32* %2 to i8*
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%17 = load i32, i32* %2
%18 = zext i32 %17 to i64
%19 = alloca i32, i64 %18
%20 = icmp sgt i32 %17, 0
br i1 %20, label %35, label %29
21: ; preds = %0, %21
%22 = phi i64 [ %25, %21 ], [ 0, %0 ]
%23 = getelementptr inbounds i32, i32* %11, i64 %22
%24 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %23)
%25 = add nuw nsw i64 %22, 1
%26 = load i32, i32* %1
%27 = sext i32 %26 to i64
%28 = icmp slt i64 %25, %27
br i1 %28, label %21, label %14
29: ; preds = %35, %14
%30 = load i32, i32* %1
%31 = icmp sgt i32 %30, 0
br i1 %31, label %32, label %43
32: ; preds = %29
%33 = bitcast i32* %3 to i8*
%34 = bitcast i32* %4 to i8*
br label %53
35: ; preds = %14, %35
%36 = phi i64 [ %39, %35 ], [ 0, %14 ]
%37 = getelementptr inbounds i32, i32* %19, i64 %36
%38 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %37)
%39 = add nuw nsw i64 %36, 1
%40 = load i32, i32* %2
%41 = sext i32 %40 to i64
%42 = icmp slt i64 %39, %41
br i1 %42, label %35, label %29
43: ; preds = %61, %29
%44 = phi i32 [ 99999, %29 ], [ %62, %61 ]
%45 = bitcast i32* %5 to i8*
%46 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %5)
%47 = load i32, i32* %5
%48 = sdiv i32 %47, %44
%49 = icmp sgt i32 %48, 0
%50 = add nsw i32 %48, -1
%51 = select i1 %49, i32 %50, i32 0
%52 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %51)
ret i32 0
53: ; preds = %32, %61
%54 = phi i64 [ 0, %32 ], [ %63, %61 ]
%55 = phi i32 [ 99999, %32 ], [ %62, %61 ]
%56 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%57 = load i32, i32* %3
%58 = icmp sgt i32 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %53
%60 = getelementptr inbounds i32, i32* %11, i64 %54
br label %67
61: ; preds = %67, %53
%62 = phi i32 [ %55, %53 ], [ %79, %67 ]
%63 = add nuw nsw i64 %54, 1
%64 = load i32, i32* %1
%65 = sext i32 %64 to i64
%66 = icmp slt i64 %63, %65
br i1 %66, label %53, label %43
67: ; preds = %59, %67
%68 = phi i32 [ 0, %59 ], [ %80, %67 ]
%69 = phi i32 [ %55, %59 ], [ %79, %67 ]
%70 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%71 = load i32, i32* %60
%72 = load i32, i32* %4
%73 = add nsw i32 %72, -1
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i32, i32* %19, i64 %74
%76 = load i32, i32* %75
%77 = add nsw i32 %76, %71
%78 = icmp slt i32 %77, %69
%79 = select i1 %78, i32 %77, i32 %69
%80 = add nuw nsw i32 %68, 1
%81 = load i32, i32* %3
%82 = icmp slt i32 %80, %81
br i1 %82, label %67, label %61
}