#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 /*<<< orphan*/ scanf(char *, int *);
int main() {
  int i, round, a = 0, b = 0, c = 0, in;
  scanf("%d", &round);
  for (i = 0; i < round; i++) {
    scanf("%d", &in);
    if (a <= b && a <= c) {
      printf("A\n");
      a += in;
    } else if (b <= c && b <= a) {
      printf("B\n");
      b += in;
    } else {
      printf("C\n");
      c += in;
    }
  }
  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,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xeb5(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1208 <main+0xe8>
lea    0xe92(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     11a9 <main+0x89>
mov    -0x10(%rbp),%eax
cmp    -0x18(%rbp),%eax
jg     11a9 <main+0x89>
lea    0xe6d(%rip),%rdi
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    11f5 <main+0xd5>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jg     11db <main+0xbb>
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     11db <main+0xbb>
lea    0xe3e(%rip),%rdi
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11f0 <main+0xd0>
lea    0xe27(%rip),%rdi
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    11f5 <main+0xd5>
jmp    11fa <main+0xda>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    115b <main+0x3b>
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
push   %rax
lea    0xece(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,0x4(%rsp)
jle    11cc <main+0xac>
xor    %ebp,%ebp
lea    0xeb0(%rip),%r14
mov    %rsp,%rbx
xor    %r12d,%r12d
xor    %r15d,%r15d
xor    %r13d,%r13d
jmp    117a <main+0x5a>
xchg   %ax,%ax
lea    0xe9c(%rip),%rdi
call   1030 <puts@plt>
add    (%rsp),%ebp
add    $0x1,%r13d
cmp    0x4(%rsp),%r13d
jge    11cc <main+0xac>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <scanf@plt>
cmp    %r12d,%r15d
jg     11b0 <main+0x90>
cmp    %ebp,%r15d
jg     11b0 <main+0x90>
lea    0xe71(%rip),%rdi
call   1030 <puts@plt>
add    (%rsp),%r15d
jmp    116f <main+0x4f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    %ebp,%r12d
jg     1160 <main+0x40>
cmp    %r15d,%r12d
jg     1160 <main+0x40>
lea    0xe44(%rip),%rdi
call   1030 <puts@plt>
add    (%rsp),%r12d
jmp    116f <main+0x4f>
xor    %eax,%eax
add    $0x8,%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 = [3 x i8] c"A\0A\00"
@.str.2 = [3 x i8] c"B\0A\00"
@.str.3 = [3 x i8] c"C\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
store i32 0, i32* %2
br label %9
9: ; preds = %47, %0
%10 = load i32, i32* %2
%11 = load i32, i32* %3
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %50
13: ; preds = %9
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %7)
%15 = load i32, i32* %4
%16 = load i32, i32* %5
%17 = icmp sle i32 %15, %16
br i1 %17, label %18, label %27
18: ; preds = %13
%19 = load i32, i32* %4
%20 = load i32, i32* %6
%21 = icmp sle i32 %19, %20
br i1 %21, label %22, label %27
22: ; preds = %18
%23 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%24 = load i32, i32* %7
%25 = load i32, i32* %4
%26 = add nsw i32 %25, %24
store i32 %26, i32* %4
br label %46
27: ; preds = %18, %13
%28 = load i32, i32* %5
%29 = load i32, i32* %6
%30 = icmp sle i32 %28, %29
br i1 %30, label %31, label %40
31: ; preds = %27
%32 = load i32, i32* %5
%33 = load i32, i32* %4
%34 = icmp sle i32 %32, %33
br i1 %34, label %35, label %40
35: ; preds = %31
%36 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%37 = load i32, i32* %7
%38 = load i32, i32* %5
%39 = add nsw i32 %38, %37
store i32 %39, i32* %5
br label %45
40: ; preds = %31, %27
%41 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%42 = load i32, i32* %7
%43 = load i32, i32* %6
%44 = add nsw i32 %43, %42
store i32 %44, i32* %6
br label %45
45: ; preds = %40, %35
br label %46
46: ; preds = %45, %22
br label %47
47: ; preds = %46
%48 = load i32, i32* %2
%49 = add nsw i32 %48, 1
store i32 %49, i32* %2
br label %9
50: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@str = [2 x i8] c"C\00"
@str.4 = [2 x i8] c"B\00"
@str.5 = [2 x i8] c"A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %40
8: ; preds = %0, %33
%9 = phi i32 [ %36, %33 ], [ 0, %0 ]
%10 = phi i32 [ %35, %33 ], [ 0, %0 ]
%11 = phi i32 [ %34, %33 ], [ 0, %0 ]
%12 = phi i32 [ %37, %33 ], [ 0, %0 ]
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%14 = icmp sgt i32 %11, %10
%15 = icmp sgt i32 %11, %9
%16 = select i1 %14, i1 true, i1 %15
br i1 %16, label %21, label %17
17: ; preds = %8
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.5, i64 0, i64 0))
%19 = load i32, i32* %2
%20 = add nsw i32 %19, %11
br label %33
21: ; preds = %8
%22 = icmp sgt i32 %10, %9
%23 = icmp sgt i32 %10, %11
%24 = select i1 %22, i1 true, i1 %23
br i1 %24, label %29, label %25
25: ; preds = %21
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.4, i64 0, i64 0))
%27 = load i32, i32* %2
%28 = add nsw i32 %27, %10
br label %33
29: ; preds = %21
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%31 = load i32, i32* %2
%32 = add nsw i32 %31, %9
br label %33
33: ; preds = %17, %29, %25
%34 = phi i32 [ %20, %17 ], [ %11, %25 ], [ %11, %29 ]
%35 = phi i32 [ %10, %17 ], [ %28, %25 ], [ %10, %29 ]
%36 = phi i32 [ %9, %17 ], [ %9, %25 ], [ %32, %29 ]
%37 = add nuw nsw i32 %12, 1
%38 = load i32, i32* %1
%39 = icmp slt i32 %37, %38
br i1 %39, label %8, label %40
40: ; preds = %33, %0
ret i32 0
}