#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() {
  int n, p, max;
  while (scanf("%d", &n), n) {
    int t[1001] = {};
    max = 0;
    while (n--) {
      scanf("%d", &p);
      t[p]++;
    }
    for (p = 1000; p > 0; p--)
      if (t[max] <= t[p])
        max = p;
    printf("%d\n", max);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xfc0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb7(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
je     120e <main+0xde>
lea    -0xfc0(%rbp),%rdi
xor    %esi,%esi
mov    $0xfa4,%edx
call   1040 <memset@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     11b4 <main+0x84>
lea    0xe6f(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
movslq -0xc(%rbp),%rax
mov    -0xfc0(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0xfc0(%rbp,%rax,4)
jmp    1176 <main+0x46>
movl   $0x3e8,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    11fa <main+0xca>
movslq -0x10(%rbp),%rax
mov    -0xfc0(%rbp,%rax,4),%eax
movslq -0xc(%rbp),%rcx
cmp    -0xfc0(%rbp,%rcx,4),%eax
jg     11e7 <main+0xb7>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    11ec <main+0xbc>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    11bb <main+0x8b>
mov    -0x10(%rbp),%esi
lea    0xdff(%rip),%rdi
call   1030 <printf@plt>
jmp    1142 <main+0x12>
xor    %eax,%eax
add    $0xfc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xfb8,%rsp
lea    0xeb8(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x8(%rsp),%ebp
test   %ebp,%ebp
je     123e <main+0x10e>
lea    0x10(%rsp),%r14
lea    0xe96(%rip),%rbx
lea    0xc(%rsp),%r15
lea    0xe8d(%rip),%r12
lea    0x8(%rsp),%r13
jmp    11a7 <main+0x77>
nopl   (%rax)
movl   $0x0,0xc(%rsp)
mov    %r12,%rdi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1050 <scanf@plt>
mov    0x8(%rsp),%ebp
test   %ebp,%ebp
je     123e <main+0x10e>
mov    $0xfa4,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
add    $0xffffffff,%ebp
mov    %ebp,0x8(%rsp)
nopl   (%rax)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
movslq 0xc(%rsp),%rax
addl   $0x1,0x10(%rsp,%rax,4)
subl   $0x1,0x8(%rsp)
jae    11c0 <main+0x90>
xor    %esi,%esi
mov    $0x3e8,%eax
jmp    11fa <main+0xca>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0xfffffffffffffffc,%rax
cmp    $0x1,%rcx
je     1180 <main+0x50>
movslq %esi,%rcx
mov    0x10(%rsp,%rcx,4),%ecx
cmp    0x10(%rsp,%rax,4),%ecx
jg     1209 <main+0xd9>
mov    %eax,%esi
movslq %esi,%rcx
mov    0x10(%rsp,%rcx,4),%ecx
cmp    0xc(%rsp,%rax,4),%ecx
jg     1219 <main+0xe9>
lea    -0x1(%rax),%esi
movslq %esi,%rcx
mov    0x10(%rsp,%rcx,4),%ecx
cmp    0x8(%rsp,%rax,4),%ecx
jg     1229 <main+0xf9>
lea    -0x2(%rax),%esi
movslq %esi,%rcx
mov    0x10(%rsp,%rcx,4),%edx
lea    -0x3(%rax),%rcx
cmp    0x4(%rsp,%rax,4),%edx
jg     11f0 <main+0xc0>
mov    %ecx,%esi
jmp    11f0 <main+0xc0>
xor    %eax,%eax
add    $0xfb8,%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 [1001 x i32]
store i32 0, i32* %1
br label %6
6: ; preds = %43, %0
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%8 = load i32, i32* %2
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %46
10: ; preds = %6
%11 = bitcast [1001 x i32]* %5 to i8*
store i32 0, i32* %4
br label %12
12: ; preds = %16, %10
%13 = load i32, i32* %2
%14 = add nsw i32 %13, -1
store i32 %14, i32* %2
%15 = icmp ne i32 %13, 0
br i1 %15, label %16, label %23
16: ; preds = %12
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [1001 x i32], [1001 x i32]* %5, i64 0, i64 %19
%21 = load i32, i32* %20
%22 = add nsw i32 %21, 1
store i32 %22, i32* %20
br label %12
23: ; preds = %12
store i32 1000, i32* %3
br label %24
24: ; preds = %40, %23
%25 = load i32, i32* %3
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %43
27: ; preds = %24
%28 = load i32, i32* %4
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [1001 x i32], [1001 x i32]* %5, i64 0, i64 %29
%31 = load i32, i32* %30
%32 = load i32, i32* %3
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [1001 x i32], [1001 x i32]* %5, i64 0, i64 %33
%35 = load i32, i32* %34
%36 = icmp sle i32 %31, %35
br i1 %36, label %37, label %39
37: ; preds = %27
%38 = load i32, i32* %3
store i32 %38, i32* %4
br label %39
39: ; preds = %37, %27
br label %40
40: ; preds = %39
%41 = load i32, i32* %3
%42 = add nsw i32 %41, -1
store i32 %42, i32* %3
br label %24
43: ; preds = %24
%44 = load i32, i32* %4
%45 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %44)
br label %6
46: ; preds = %6
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 [1001 x i32]
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = icmp eq i32 %7, 0
br i1 %8, label %69, label %9
9: ; preds = %0
%10 = bitcast [1001 x i32]* %3 to i8*
br label %11
11: ; preds = %64, %9
%12 = phi i32 [ %7, %9 ], [ %67, %64 ]
%13 = add nsw i32 %12, -1
store i32 %13, i32* %1
br label %14
14: ; preds = %11, %14
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%16 = load i32, i32* %2
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [1001 x i32], [1001 x i32]* %3, i64 0, i64 %17
%19 = load i32, i32* %18
%20 = add nsw i32 %19, 1
store i32 %20, i32* %18
%21 = load i32, i32* %1
%22 = add nsw i32 %21, -1
store i32 %22, i32* %1
%23 = icmp eq i32 %21, 0
br i1 %23, label %24, label %14
24: ; preds = %14, %24
%25 = phi i64 [ %62, %24 ], [ 1000, %14 ]
%26 = phi i32 [ %61, %24 ], [ 0, %14 ]
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [1001 x i32], [1001 x i32]* %3, i64 0, i64 %27
%29 = load i32, i32* %28
%30 = getelementptr inbounds [1001 x i32], [1001 x i32]* %3, i64 0, i64 %25
%31 = load i32, i32* %30
%32 = icmp sgt i32 %29, %31
%33 = trunc i64 %25 to i32
%34 = select i1 %32, i32 %26, i32 %33
%35 = add nsw i64 %25, -1
%36 = sext i32 %34 to i64
%37 = getelementptr inbounds [1001 x i32], [1001 x i32]* %3, i64 0, i64 %36
%38 = load i32, i32* %37
%39 = getelementptr inbounds [1001 x i32], [1001 x i32]* %3, i64 0, i64 %35
%40 = load i32, i32* %39
%41 = icmp sgt i32 %38, %40
%42 = trunc i64 %35 to i32
%43 = select i1 %41, i32 %34, i32 %42
%44 = add nsw i64 %25, -2
%45 = sext i32 %43 to i64
%46 = getelementptr inbounds [1001 x i32], [1001 x i32]* %3, i64 0, i64 %45
%47 = load i32, i32* %46
%48 = getelementptr inbounds [1001 x i32], [1001 x i32]* %3, i64 0, i64 %44
%49 = load i32, i32* %48
%50 = icmp sgt i32 %47, %49
%51 = trunc i64 %44 to i32
%52 = select i1 %50, i32 %43, i32 %51
%53 = add nsw i64 %25, -3
%54 = sext i32 %52 to i64
%55 = getelementptr inbounds [1001 x i32], [1001 x i32]* %3, i64 0, i64 %54
%56 = load i32, i32* %55
%57 = getelementptr inbounds [1001 x i32], [1001 x i32]* %3, i64 0, i64 %53
%58 = load i32, i32* %57
%59 = icmp sgt i32 %56, %58
%60 = trunc i64 %53 to i32
%61 = select i1 %59, i32 %52, i32 %60
%62 = add nsw i64 %25, -4
%63 = icmp eq i64 %53, 1
br i1 %63, label %64, label %24
64: ; preds = %24
store i32 0, i32* %2
%65 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %61)
%66 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%67 = load i32, i32* %1
%68 = icmp eq i32 %67, 0
br i1 %68, label %69, label %11
69: ; preds = %64, %0
ret i32 0
}