#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 *, char *);
size_t strlen(char *);
int main() {
  char b[51];
  scanf("%s", b);
  size_t len = strlen(b);
  int ball = 1;
  for (int i = 0; i < len; i++) {
    ball = b[i] == 'A' ? (ball == 1 ? 2 : (ball == 2 ? 1 : 3))
                       : (b[i] == 'B' ? (ball == 2 ? 3 : (ball == 3 ? 2 : 1))
                                      : (ball == 1 ? 3 : (ball == 3 ? 1 : 2)));
  }
  printf("%d\n", ball);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x40(%rbp),%rsi
lea    0xeb6(%rip),%rdi
call   1050 <scanf@plt>
lea    -0x40(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x48(%rbp)
movl   $0x1,-0x4c(%rbp)
movl   $0x0,-0x50(%rbp)
movslq -0x50(%rbp),%rax
cmp    -0x48(%rbp),%rax
jae    1259 <main+0x129>
movslq -0x50(%rbp),%rax
movsbl -0x40(%rbp,%rax,1),%eax
cmp    $0x41,%eax
jne    11c2 <main+0x92>
cmpl   $0x1,-0x4c(%rbp)
jne    11a1 <main+0x71>
mov    $0x2,%eax
mov    %eax,-0x54(%rbp)
jmp    11b7 <main+0x87>
mov    -0x4c(%rbp),%edx
mov    $0x3,%eax
mov    $0x1,%ecx
cmp    $0x2,%edx
cmove  %ecx,%eax
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
mov    %eax,-0x58(%rbp)
jmp    1245 <main+0x115>
movslq -0x50(%rbp),%rax
movsbl -0x40(%rbp,%rax,1),%eax
cmp    $0x42,%eax
jne    120c <main+0xdc>
cmpl   $0x2,-0x4c(%rbp)
jne    11eb <main+0xbb>
mov    $0x3,%eax
mov    %eax,-0x5c(%rbp)
jmp    1201 <main+0xd1>
mov    -0x4c(%rbp),%edx
mov    $0x1,%eax
mov    $0x2,%ecx
cmp    $0x3,%edx
cmove  %ecx,%eax
mov    %eax,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
mov    %eax,-0x60(%rbp)
jmp    123f <main+0x10f>
cmpl   $0x1,-0x4c(%rbp)
jne    1223 <main+0xf3>
mov    $0x3,%eax
mov    %eax,-0x64(%rbp)
jmp    1239 <main+0x109>
mov    -0x4c(%rbp),%edx
mov    $0x2,%eax
mov    $0x1,%ecx
cmp    $0x3,%edx
cmove  %ecx,%eax
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%eax
mov    %eax,-0x60(%rbp)
mov    -0x60(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x58(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    116a <main+0x3a>
mov    -0x4c(%rbp),%esi
lea    0xda0(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x40,%rsp
lea    0xec4(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1050 <scanf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %rax,%rax
je     11ec <main+0xbc>
mov    $0x1,%edx
xor    %ecx,%ecx
jmp    117b <main+0x4b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rcx
mov    %esi,%edx
cmp    %rcx,%rax
je     11f1 <main+0xc1>
movzbl (%rsp,%rcx,1),%ebx
cmp    $0x42,%bl
je     11b0 <main+0x80>
cmp    $0x41,%bl
jne    11d0 <main+0xa0>
mov    $0x2,%esi
cmp    $0x1,%edx
je     1170 <main+0x40>
xor    %esi,%esi
cmp    $0x2,%edx
setne  %sil
add    %esi,%esi
add    $0x1,%esi
jmp    1170 <main+0x40>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x3,%esi
cmp    $0x2,%edx
je     1170 <main+0x40>
xor    %esi,%esi
cmp    $0x3,%edx
sete   %sil
add    $0x1,%esi
jmp    1170 <main+0x40>
nopl   0x0(%rax,%rax,1)
mov    $0x3,%esi
cmp    $0x1,%edx
je     1170 <main+0x40>
xor    %edi,%edi
cmp    $0x3,%edx
sete   %dil
mov    $0x2,%esi
sub    %edi,%esi
jmp    1170 <main+0x40>
mov    $0x1,%esi
lea    0xe0b(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
ret

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

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