#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 *, int);
scalar_t__ scanf(char *, ...);
int main(void) {
  char cmd[5];
  int x = 0, y, gift = 0;
  scanf("%*d");
  while (scanf("%s", cmd) != EOF) {
    switch (cmd[0]) {
    case 'L':
      x--;
      break;
    case 'R':
      x++;
      break;
    default:
      scanf("%d", &y);
      if (x == y)
        gift++;
    }
  }
  printf("%d\n", gift);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
lea    -0x9(%rbp),%rsi
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    0x2e84(%rip),%rcx
cmp    (%rcx),%rax
je     11e0 <main+0xc0>
movsbl -0x9(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x4c,%eax
je     1193 <main+0x73>
jmp    1182 <main+0x62>
mov    -0x1c(%rbp),%eax
sub    $0x52,%eax
je     11a1 <main+0x81>
jmp    11af <main+0x8f>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    11db <main+0xbb>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11db <main+0xbb>
lea    0xe51(%rip),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    11d6 <main+0xb6>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11db <main+0xbb>
jmp    114b <main+0x2b>
mov    -0x18(%rbp),%esi
lea    0xe20(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%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    0xecb(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <scanf@plt>
lea    0xebf(%rip),%rdi
lea    0xf(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x2e90(%rip),%rbp
cmp    0x0(%rbp),%rax
jne    117d <main+0x5d>
lea    0xea5(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe80(%rip),%r14
lea    0xf(%rsp),%r15
lea    0x14(%rsp),%r13
xor    %ebx,%ebx
xor    %r12d,%r12d
jmp    11d0 <main+0xb0>
cs nopw 0x0(%rax,%rax,1)
nop
lea    0xe60(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
xor    %eax,%eax
cmp    0x14(%rsp),%r12d
sete   %al
add    %eax,%ebx
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
cmp    0x0(%rbp),%rax
je     115e <main+0x3e>
movsbl 0xf(%rsp),%eax
cmp    $0x52,%eax
je     11f0 <main+0xd0>
cmp    $0x4c,%eax
jne    11a0 <main+0x80>
add    $0xffffffff,%r12d
jmp    11bd <main+0x9d>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%r12d
jmp    11bd <main+0x9d>

LLVM IR (-O0):
@.str = [4 x i8] c"%*d\00"
@.str.1 = [3 x i8] c"%s\00"
@EOF = global i64 0
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [5 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
store i32 0, i32* %5
%6 = call i64 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %31, %0
%8 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%9 = call i64 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%10 = load i64, i64* @EOF
%11 = icmp ne i64 %9, %10
br i1 %11, label %12, label %32
12: ; preds = %7
%13 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
switch i32 %15, label %22 [
i32 76, label %16
i32 82, label %19
]
16: ; preds = %12
%17 = load i32, i32* %3
%18 = add nsw i32 %17, -1
store i32 %18, i32* %3
br label %31
19: ; preds = %12
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
store i32 %21, i32* %3
br label %31
22: ; preds = %12
%23 = call i64 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%24 = load i32, i32* %3
%25 = load i32, i32* %4
%26 = icmp eq i32 %24, %25
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
br label %30
30: ; preds = %27, %22
br label %31
31: ; preds = %30, %19, %16
br label %7
32: ; preds = %7
%33 = load i32, i32* %5
%34 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %33)
ret i32 0
}

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