#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, char *);
int /*<<< orphan*/ scanf(char *, ...);
scalar_t__ walk(int, int *, int, int);
int main() {
  int x = 0, y = 0;
  scanf("%d %d", &x, &y);
  int count = 0;
  scanf("%d", &count);
  int commands[count];
  char buffer[8];
  for (int i = 0; i < count; i++) {
    scanf("%s", buffer);
    commands[i] = buffer[0] == 'F' ? 0 : buffer[0] == 'L' ? -1 : 1;
  }
  for (int i = 0; i < count; i++) {
    int original = commands[i];
    int found = 0;
    for (int z = -1; z < 2; z++) {
      if (z != original) {
        commands[i] = z;
        if (walk(count, commands, x, y)) {
          printf("%d %s\n", i + 1, !z ? "Forward" : z < 0 ? "Left" : "Right");
          found = 1;
        }
      }
      if (found)
        break;
    }
    if (found)
      break;
    commands[i] = original;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xeac(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x49(%rbp)
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1040 <scanf@plt>
mov    -0x49(%rbp),%al
movl   $0x0,-0x10(%rbp)
lea    0xe8c(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x10(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1216 <main+0xe6>
lea    -0x28(%rbp),%rsi
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
movsbl -0x28(%rbp),%eax
cmp    $0x46,%eax
jne    11e3 <main+0xb3>
xor    %eax,%eax
mov    %eax,-0x50(%rbp)
jmp    11fa <main+0xca>
movsbl -0x28(%rbp),%edx
mov    $0x1,%eax
mov    $0xffffffff,%ecx
cmp    $0x4c,%edx
cmove  %ecx,%eax
mov    %eax,-0x50(%rbp)
mov    -0x48(%rbp),%rax
mov    -0x50(%rbp),%edx
movslq -0x2c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11ae <main+0x7e>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    132c <main+0x1fc>
mov    -0x48(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0xffffffff,-0x3c(%rbp)
cmpl   $0x2,-0x3c(%rbp)
jge    1301 <main+0x1d1>
mov    -0x3c(%rbp),%eax
cmp    -0x34(%rbp),%eax
je     12df <main+0x1af>
mov    -0x48(%rbp),%rsi
mov    -0x3c(%rbp),%ecx
movslq -0x30(%rbp),%rax
mov    %ecx,(%rsi,%rax,4)
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
call   1050 <walk@plt>
cmp    $0x0,%rax
je     12da <main+0x1aa>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jne    12a4 <main+0x174>
lea    0xd75(%rip),%rax
mov    %rax,-0x60(%rbp)
jmp    12c0 <main+0x190>
mov    -0x3c(%rbp),%edx
lea    0xd6f(%rip),%rax
lea    0xd63(%rip),%rcx
cmp    $0x0,%edx
cmovl  %rcx,%rax
mov    %rax,-0x60(%rbp)
mov    -0x54(%rbp),%esi
mov    -0x60(%rbp),%rdx
lea    0xd3b(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x38(%rbp)
jmp    12df <main+0x1af>
cmpl   $0x0,-0x38(%rbp)
je     12ee <main+0x1be>
jmp    1301 <main+0x1d1>
jmp    12f3 <main+0x1c3>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1245 <main+0x115>
cmpl   $0x0,-0x38(%rbp)
je     1310 <main+0x1e0>
jmp    132c <main+0x1fc>
mov    -0x48(%rbp),%rax
mov    -0x34(%rbp),%edx
movslq -0x30(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    121d <main+0xed>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%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    $0x28,%rsp
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x30(%rbp)
lea    0xeaa(%rip),%rdi
xor    %r13d,%r13d
lea    -0x34(%rbp),%rsi
lea    -0x30(%rbp),%rdx
xor    %eax,%eax
call   1040 <scanf@plt>
movl   $0x0,-0x2c(%rbp)
lea    0xe8d(%rip),%rdi
lea    -0x2c(%rbp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    %rsp,%r12
mov    -0x2c(%rbp),%eax
mov    %rsp,%r14
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
cmpl   $0x0,-0x2c(%rbp)
jle    12b3 <main+0x183>
mov    %r12,-0x40(%rbp)
lea    0xe55(%rip),%r15
lea    -0x48(%rbp),%rbx
xor    %r12d,%r12d
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
movzbl -0x48(%rbp),%eax
xor    %ecx,%ecx
cmp    $0x4c,%al
setne  %cl
cmp    $0x46,%al
lea    -0x1(%rcx,%rcx,1),%eax
cmove  %r13d,%eax
mov    %eax,(%r14,%r12,4)
add    $0x1,%r12
movslq -0x2c(%rbp),%rdi
cmp    %rdi,%r12
jl     11c0 <main+0x90>
test   %edi,%edi
mov    -0x40(%rbp),%r12
jle    12b3 <main+0x183>
xor    %ebx,%ebx
lea    0xe10(%rip),%r15
jmp    123f <main+0x10f>
nopw   0x0(%rax,%rax,1)
movl   $0x1,(%r14,%rbx,4)
mov    -0x2c(%rbp),%edi
mov    -0x34(%rbp),%edx
mov    -0x30(%rbp),%ecx
mov    %r14,%rsi
call   1050 <walk@plt>
test   %rax,%rax
jne    1298 <main+0x168>
mov    %r13d,(%r14,%rbx,4)
add    $0x1,%rbx
movslq -0x2c(%rbp),%rdi
cmp    %rdi,%rbx
jge    12b3 <main+0x183>
mov    (%r14,%rbx,4),%r13d
cmp    $0xffffffff,%r13d
je     1269 <main+0x139>
movl   $0xffffffff,(%r14,%rbx,4)
ff
mov    -0x34(%rbp),%edx
mov    -0x30(%rbp),%ecx
mov    %r14,%rsi
call   1050 <walk@plt>
test   %rax,%rax
jne    129f <main+0x16f>
test   %r13d,%r13d
je     1210 <main+0xe0>
movl   $0x0,(%r14,%rbx,4)
mov    -0x2c(%rbp),%edi
mov    -0x34(%rbp),%edx
mov    -0x30(%rbp),%ecx
mov    %r14,%rsi
call   1050 <walk@plt>
test   %rax,%rax
jne    128f <main+0x15f>
cmp    $0x1,%r13d
jne    1210 <main+0xe0>
jmp    122e <main+0xfe>
lea    0xd7a(%rip),%r15
jmp    129f <main+0x16f>
lea    0xd7e(%rip),%r15
add    $0x1,%ebx
lea    0xd60(%rip),%rdi
mov    %ebx,%esi
mov    %r15,%rdx
call   1030 <printf@plt>
mov    %r12,%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 = [6 x i8] c"%d %d\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [7 x i8] c"%d %s\0A\00"
@.str.4 = [8 x i8] c"Forward\00"
@.str.5 = [5 x i8] c"Left\00"
@.str.6 = [6 x i8] c"Right\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca [8 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %3)
store i32 0, i32* %4
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%15 = load i32, i32* %4
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %5
%18 = alloca i32, i64 %16
store i64 %16, i64* %6
store i32 0, i32* %8
br label %19
19: ; preds = %43, %0
%20 = load i32, i32* %8
%21 = load i32, i32* %4
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %46
23: ; preds = %19
%24 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%25 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %24)
%26 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 70
br i1 %29, label %30, label %31
30: ; preds = %23
br label %38
31: ; preds = %23
%32 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 76
%36 = zext i1 %35 to i64
%37 = select i1 %35, i32 -1, i32 1
br label %38
38: ; preds = %31, %30
%39 = phi i32 [ 0, %30 ], [ %37, %31 ]
%40 = load i32, i32* %8
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32, i32* %18, i64 %41
store i32 %39, i32* %42
br label %43
43: ; preds = %38
%44 = load i32, i32* %8
%45 = add nsw i32 %44, 1
store i32 %45, i32* %8
br label %19
46: ; preds = %19
store i32 0, i32* %9
br label %47
47: ; preds = %105, %46
%48 = load i32, i32* %9
%49 = load i32, i32* %4
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %108
51: ; preds = %47
%52 = load i32, i32* %9
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i32, i32* %18, i64 %53
%55 = load i32, i32* %54
store i32 %55, i32* %10
store i32 0, i32* %11
store i32 -1, i32* %12
br label %56
56: ; preds = %93, %51
%57 = load i32, i32* %12
%58 = icmp slt i32 %57, 2
br i1 %58, label %59, label %96
59: ; preds = %56
%60 = load i32, i32* %12
%61 = load i32, i32* %10
%62 = icmp ne i32 %60, %61
br i1 %62, label %63, label %88
63: ; preds = %59
%64 = load i32, i32* %12
%65 = load i32, i32* %9
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i32, i32* %18, i64 %66
store i32 %64, i32* %67
%68 = load i32, i32* %4
%69 = load i32, i32* %2
%70 = load i32, i32* %3
%71 = call i64 @walk(i32 %68, i32* %18, i32 %69, i32 %70)
%72 = icmp ne i64 %71, 0
br i1 %72, label %73, label %87
73: ; preds = %63
%74 = load i32, i32* %9
%75 = add nsw i32 %74, 1
%76 = load i32, i32* %12
%77 = icmp ne i32 %76, 0
br i1 %77, label %79, label %78
78: ; preds = %73
br label %84
79: ; preds = %73
%80 = load i32, i32* %12
%81 = icmp slt i32 %80, 0
%82 = zext i1 %81 to i64
%83 = select i1 %81, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0)
br label %84
84: ; preds = %79, %78
%85 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), %78 ], [ %83, %79 ]
%86 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %75, i8* %85)
store i32 1, i32* %11
br label %87
87: ; preds = %84, %63
br label %88
88: ; preds = %87, %59
%89 = load i32, i32* %11
%90 = icmp ne i32 %89, 0
br i1 %90, label %91, label %92
91: ; preds = %88
br label %96
92: ; preds = %88
br label %93
93: ; preds = %92
%94 = load i32, i32* %12
%95 = add nsw i32 %94, 1
store i32 %95, i32* %12
br label %56
96: ; preds = %91, %56
%97 = load i32, i32* %11
%98 = icmp ne i32 %97, 0
br i1 %98, label %99, label %100
99: ; preds = %96
br label %108
100: ; preds = %96
%101 = load i32, i32* %10
%102 = load i32, i32* %9
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds i32, i32* %18, i64 %103
store i32 %101, i32* %104
br label %105
105: ; preds = %100
%106 = load i32, i32* %9
%107 = add nsw i32 %106, 1
store i32 %107, i32* %9
br label %47
108: ; preds = %99, %47
store i32 0, i32* %1
%109 = load i8*, i8** %5
%110 = load i32, i32* %1
ret i32 %110
}

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