#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 *calloc(int, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n;
  int most_common_type = 0;
  int most_common_amount = 0;
  scanf("%d", &n);
  int *birds = calloc(n + 1, sizeof(int));
  for (int i = 0; i < n; i++) {
    int type;
    scanf("%d", &type);
    birds[type] += 1;
    if (birds[type] > most_common_amount) {
      most_common_amount = birds[type];
      most_common_type = type;
    }
    if (birds[type] == most_common_amount && type < most_common_type) {
      most_common_type = type;
    }
  }
  printf("%d", most_common_type);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xeac(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x8(%rbp),%edi
add    $0x1,%edi
mov    $0x4,%esi
call   1040 <calloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1206 <main+0xd6>
lea    0xe75(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x10(%rbp),%eax
jle    11cd <main+0x9d>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x10(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x10(%rbp),%eax
jne    11f3 <main+0xc3>
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11f3 <main+0xc3>
mov    -0x20(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    11f8 <main+0xc8>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1178 <main+0x48>
mov    -0xc(%rbp),%esi
lea    0xdf0(%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
push   %rax
lea    0xebe(%rip),%rdi
mov    %rsp,%rsi
call   1050 <scanf@plt>
mov    (%rsp),%ebx
lea    0x1(%rbx),%edi
mov    $0x4,%esi
call   1040 <calloc@plt>
test   %ebx,%ebx
jle    11bb <main+0x8b>
mov    %rax,%r12
xor    %ebx,%ebx
lea    0xe96(%rip),%r14
lea    0x4(%rsp),%r15
xor    %ebp,%ebp
xor    %r13d,%r13d
jmp    118e <main+0x5e>
cs nopw 0x0(%rax,%rax,1)
cmp    %r13d,%ecx
cmove  %eax,%ebp
add    $0x1,%ebx
cmp    (%rsp),%ebx
jge    11bd <main+0x8d>
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
movslq 0x4(%rsp),%rax
mov    (%r12,%rax,4),%edx
lea    0x1(%rdx),%ecx
cmp    %r13d,%edx
cmovge %ecx,%r13d
mov    %ecx,(%r12,%rax,4)
cmovge %eax,%ebp
cmp    %ebp,%eax
jl     1180 <main+0x50>
mov    %ebp,%eax
jmp    1180 <main+0x50>
xor    %ebp,%ebp
lea    0xe3c(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
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"
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* %3
store i32 0, i32* %4
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%9 = load i32, i32* %2
%10 = add nsw i32 %9, 1
%11 = call i32* @calloc(i32 %10, i32 4)
store i32* %11, i32** %5
store i32 0, i32* %6
br label %12
12: ; preds = %53, %0
%13 = load i32, i32* %6
%14 = load i32, i32* %2
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %56
16: ; preds = %12
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %7)
%18 = load i32*, i32** %5
%19 = load i32, i32* %7
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i32, i32* %18, i64 %20
%22 = load i32, i32* %21
%23 = add nsw i32 %22, 1
store i32 %23, i32* %21
%24 = load i32*, i32** %5
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %24, i64 %26
%28 = load i32, i32* %27
%29 = load i32, i32* %4
%30 = icmp sgt i32 %28, %29
br i1 %30, label %31, label %38
31: ; preds = %16
%32 = load i32*, i32** %5
%33 = load i32, i32* %7
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %32, i64 %34
%36 = load i32, i32* %35
store i32 %36, i32* %4
%37 = load i32, i32* %7
store i32 %37, i32* %3
br label %38
38: ; preds = %31, %16
%39 = load i32*, i32** %5
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32, i32* %39, i64 %41
%43 = load i32, i32* %42
%44 = load i32, i32* %4
%45 = icmp eq i32 %43, %44
br i1 %45, label %46, label %52
46: ; preds = %38
%47 = load i32, i32* %7
%48 = load i32, i32* %3
%49 = icmp slt i32 %47, %48
br i1 %49, label %50, label %52
50: ; preds = %46
%51 = load i32, i32* %7
store i32 %51, i32* %3
br label %52
52: ; preds = %50, %46, %38
br label %53
53: ; preds = %52
%54 = load i32, i32* %6
%55 = add nsw i32 %54, 1
store i32 %55, i32* %6
br label %12
56: ; preds = %12
%57 = load i32, i32* %3
%58 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %57)
ret i32 0
}

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