#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__ eh_buraco(int, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *);
int main(int argc, char *noargs[]) {
  int i, m, res, N, pos[2] = {4, 3};
  int moves[9][2] = {
      {0, 0},   {1, 2},   {2, 1},  {2, -1}, {1, -2},
      {-1, -2}, {-2, -1}, {-2, 1}, {-1, 2},
  };
  scanf("%d", &N);
  res = N;
  for (i = 0; i < N; ++i) {
    scanf("%d", &m);
    pos[0] += moves[m][0];
    pos[1] += moves[m][1];
    if (eh_buraco(pos[0], pos[1])) {
      res = i + 1;
      break;
    }
  }
  printf("%d\n", res);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xea3(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    -0x70(%rbp),%rdi
lea    0xea4(%rip),%rsi
mov    $0x48,%edx
call   1050 <memcpy@plt>
lea    0xedb(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1201 <main+0xc1>
lea    0xeb2(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <scanf@plt>
movslq -0x18(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%eax
add    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
movslq -0x18(%rbp),%rax
mov    -0x6c(%rbp,%rax,8),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x28(%rbp),%edi
mov    -0x24(%rbp),%esi
call   1040 <eh_buraco@plt>
cmp    $0x0,%rax
je     11ee <main+0xae>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1201 <main+0xc1>
jmp    11f3 <main+0xb3>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1193 <main+0x53>
mov    -0x1c(%rbp),%esi
lea    0xe50(%rip),%rdi
call   1030 <printf@plt>
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    $0x18,%rsp
lea    0xf03(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%esi
test   %esi,%esi
jle    11be <main+0x8e>
mov    %esi,0x10(%rsp)
mov    $0x3,%ebp
mov    $0x4,%ebx
mov    $0x1,%r13d
lea    0xed6(%rip),%r15
lea    0x14(%rsp),%r12
lea    0xe82(%rip),%r14
xchg   %ax,%ax
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <scanf@plt>
movslq 0x14(%rsp),%rax
add    (%r14,%rax,8),%ebx
add    0x4(%r14,%rax,8),%ebp
mov    %ebx,%edi
mov    %ebp,%esi
call   1040 <eh_buraco@plt>
test   %rax,%rax
jne    11bb <main+0x8b>
lea    0x1(%r13),%eax
cmp    0xc(%rsp),%r13d
mov    %eax,%r13d
jl     1180 <main+0x50>
mov    0x10(%rsp),%esi
jmp    11be <main+0x8e>
mov    %r13d,%esi
lea    0xe86(%rip),%rdi
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):
@__const.main.pos = [2 x i32] [i32 4, i32 3]
@__const.main.moves = [9 x [2 x i32]] [[2 x i32] zeroinitializer, [2 x i32] [i32 1, i32 2], [2 x i32] [i32 2, i32 1], [2 x i32] [i32 2, i32 -1], [2 x i32] [i32 1, i32 -2], [2 x i32] [i32 -1, i32 -2], [2 x i32] [i32 -2, i32 -1], [2 x i32] [i32 -2, i32 1], [2 x i32] [i32 -1, i32 2]]
@.str = [3 x i8] c"%d\00"
@.str.1 = [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 [2 x i32]
%11 = alloca [9 x [2 x i32]]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = bitcast [2 x i32]* %10 to i8*
%13 = bitcast [9 x [2 x i32]]* %11 to i8*
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %9)
%15 = load i32, i32* %9
store i32 %15, i32* %8
store i32 0, i32* %6
br label %16
16: ; preds = %48, %2
%17 = load i32, i32* %6
%18 = load i32, i32* %9
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %51
20: ; preds = %16
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %7)
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [9 x [2 x i32]], [9 x [2 x i32]]* %11, i64 0, i64 %23
%25 = getelementptr inbounds [2 x i32], [2 x i32]* %24, i64 0, i64 0
%26 = load i32, i32* %25
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 0
%28 = load i32, i32* %27
%29 = add nsw i32 %28, %26
store i32 %29, i32* %27
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [9 x [2 x i32]], [9 x [2 x i32]]* %11, i64 0, i64 %31
%33 = getelementptr inbounds [2 x i32], [2 x i32]* %32, i64 0, i64 1
%34 = load i32, i32* %33
%35 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 1
%36 = load i32, i32* %35
%37 = add nsw i32 %36, %34
store i32 %37, i32* %35
%38 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 0
%39 = load i32, i32* %38
%40 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 1
%41 = load i32, i32* %40
%42 = call i64 @eh_buraco(i32 %39, i32 %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %20
%45 = load i32, i32* %6
%46 = add nsw i32 %45, 1
store i32 %46, i32* %8
br label %51
47: ; preds = %20
br label %48
48: ; preds = %47
%49 = load i32, i32* %6
%50 = add nsw i32 %49, 1
store i32 %50, i32* %6
br label %16
51: ; preds = %44, %16
%52 = load i32, i32* %8
%53 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %52)
ret i32 0
}

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