#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 scanf(char *, int *);
int main() {
  while (1) {
    int n;
    if (scanf("%d", &n) != 1)
      break;
    int c;
    scanf("%d", &c);
    int o = 1;
    int t;
    while (--n) {
      scanf("%d", &t);
      if (t == c) {
        ++o;
      } else {
        --o;
        if (o == -1) {
          c = t;
          o = 1;
        }
      }
    }
    printf("%d\n", c);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmp    $0x1,%eax
je     114d <main+0x2d>
jmp    11de <main+0xbe>
lea    0xeac(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x1,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
je     11ca <main+0xaa>
lea    0xe83(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    11a0 <main+0x80>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11c5 <main+0xa5>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    11c0 <main+0xa0>
mov    -0x14(%rbp),%eax
mov    %eax,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
jmp    11c5 <main+0xa5>
jmp    1164 <main+0x44>
mov    -0xc(%rbp),%esi
lea    0xe2f(%rip),%rdi
call   1030 <printf@plt>
jmp    112f <main+0xf>
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
lea    0x10(%rsp),%rsi
call   1040 <scanf@plt>
cmp    $0x1,%eax
jne    11e3 <main+0xc3>
lea    0xeb1(%rip),%rbx
lea    0xc(%rsp),%r14
lea    0xea8(%rip),%r15
lea    0x10(%rsp),%r12
lea    0x14(%rsp),%r13
jmp    118c <main+0x6c>
nopw   0x0(%rax,%rax,1)
mov    0xc(%rsp),%esi
mov    %r15,%rdi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <scanf@plt>
cmp    $0x1,%eax
jne    11e3 <main+0xc3>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <scanf@plt>
addl   $0xffffffff,0x10(%rsp)
je     1170 <main+0x50>
mov    $0x1,%ebp
jmp    11bc <main+0x9c>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%ebp
mov    %eax,%esi
addl   $0xffffffff,0x10(%rsp)
je     1174 <main+0x54>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1040 <scanf@plt>
mov    0x14(%rsp),%eax
mov    0xc(%rsp),%esi
cmp    %esi,%eax
je     11b0 <main+0x90>
sub    $0x1,%ebp
jae    11b5 <main+0x95>
mov    %eax,0xc(%rsp)
mov    $0x1,%ebp
jmp    11b3 <main+0x93>
xor    %eax,%eax
add    $0x18,%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 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
br label %6
6: ; preds = %0, %33
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%8 = icmp ne i32 %7, 1
br i1 %8, label %9, label %10
9: ; preds = %6
br label %36
10: ; preds = %6
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
store i32 1, i32* %4
br label %12
12: ; preds = %32, %10
%13 = load i32, i32* %2
%14 = add nsw i32 %13, -1
store i32 %14, i32* %2
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %33
16: ; preds = %12
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %5)
%18 = load i32, i32* %5
%19 = load i32, i32* %3
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = load i32, i32* %4
%23 = add nsw i32 %22, 1
store i32 %23, i32* %4
br label %32
24: ; preds = %16
%25 = load i32, i32* %4
%26 = add nsw i32 %25, -1
store i32 %26, i32* %4
%27 = load i32, i32* %4
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = load i32, i32* %5
store i32 %30, i32* %3
store i32 1, i32* %4
br label %31
31: ; preds = %29, %24
br label %32
32: ; preds = %31, %21
br label %12
33: ; preds = %12
%34 = load i32, i32* %3
%35 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %34)
br label %6
36: ; preds = %9
ret i32 0
}

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