After celebrating the midcourse the students of one of the faculties of the Berland State University decided to conduct a vote for the best photo. They published the photos in the social network and agreed on the rules to choose a winner: the photo which gets most likes wins. If multiple photoes get most likes, the winner is the photo that gets this number first.

Help guys determine the winner photo by the records of likes.


-----Input-----

The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the total likes to the published photoes. 

The second line contains n positive integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 1 000 000), where a_{i} is the identifier of the photo which got the i-th like.


-----Output-----

Print the identifier of the photo which won the elections.


-----Examples-----
Input
5
1 3 2 2 1

Output
2

Input
9
100 200 300 200 100 300 300 100 200

Output
300



-----Note-----

In the first test sample the photo with id 1 got two likes (first and fifth), photo with id 2 got two likes (third and fourth), and photo with id 3 got one like (second). 

Thus, the winner is the photo with identifier 2, as it got:  more likes than the photo with id 3;  as many likes as the photo with id 1, but the photo with the identifier 2 got its second like earlier.

Difficulty: EASY

Solutions:
n = [int(i) for i in input().split()][0]
a = [int(i) for i in input().split()]
mydic = {}
max = 0
maxind = 0
for i in range(n):
	mydic[a[i]] = mydic.get(a[i], 0) + 1
	if mydic[a[i]] > max:
		max = mydic[a[i]]
		maxind = a[i]
print(maxind)


def run(n, arr):
	photos = []
	top = dict(id=arr.pop(0), likes=1)
	photos.append(top)
	for id in arr:
		found = False
		for photo in photos:
			if photo['id'] == id:
				found = True
				photo['likes'] += 1
				if photo['likes'] > top['likes']:
					top = photo
				break
		if not found:
			photos.append(dict(id=id, likes=1))
	return top['id']

def read_data():
	n = int(input())
	arr = [int(x) for x in input().split(' ')]
	return (n, arr)
(n, arr) = read_data()
print(run(n, arr))


import math
n = int(input())
a = input().split()
b = dict()
res = -1
resl = -1
for i in range(n):
	cur = a[i]
	if cur in b.keys():
		b[cur] += 1
	else:
		b[cur] = 1
	if b[cur] > resl:
		res = cur
		resl = b[cur]
print(res)


n = int(input())
ids = list(map(int, input().split()))
d = {}
for i in range(0, n):
	if d.get(ids[i]) == None:
		d[ids[i]] = (0, i)
	else:
		d[ids[i]] = (d[ids[i]][0] + 1, i)
max = ids[0]
for i in range(0, n):
	if d[ids[i]][0] > d[max][0]:
		max = ids[i]
	elif d[ids[i]][0] == d[max][0]:
		if d[ids[i]][1] < d[max][1]:
			max = ids[i]
print(max)


n = int(input())
a = [int(v) for v in input().split()]
c = [0] * 1000000
l = [0] * 1000000
for i in range(len(a)):
	c[a[i] - 1] += 1
	l[a[i] - 1] = i + 1
k = 0
for i in range(1, 1000000):
	if c[i] > c[k] or (c[i] == c[k] and l[i] < l[k]):
		k = i
print(k + 1)


n = input()
a = list(map(int, input().split()))
d = {}
mx = 0
ans = -1
for x in a:
	d[x] = d.get(x, 0) + 1
	if d[x] > mx:
		mx = d[x]
		ans = x
print(ans)


n = int(input())
per = 0
ind = 0
A = dict()
s = input().split()
for i in s:
	if i not in A:
		A[i] = 1
		if per == 0:
			per = 1
			ind = i
	else:
		A[i] += 1
		if A[i] > per:
			ind = i
			per = A[i]
print(ind)


import collections
n = int(input())
s = [int(i) for i in input().split()]
d = collections.Counter()
g = 0
h = 0
for i in s:
	d[i] += 1
	p = d.most_common(1)[0][1]
	y = d.most_common(1)[0][0]
	if p > g:
		h = y
		g = p
print(h)


likes_count = {}
max_likes_count = 0
max_photo_id = None
_ = input()
for photo_id in input().split():
	if photo_id in likes_count:
		likes_count[photo_id] += 1
	else:
		likes_count[photo_id] = 1
	if likes_count[photo_id] > max_likes_count:
		max_likes_count = likes_count[photo_id]
		max_photo_id = photo_id
print(max_photo_id)


from functools import reduce
a = int(input())
b = list(map(lambda m: int(m), input().split(' ')))
m = max([len(list(filter(lambda m: m == i, b))) for i in b])
v = {a: 0 for a in b}
for i in b:
	v[i] += 1
	if v[i] == m:
		print(i)
		exit(0)


from collections import Counter
n = int(input())
arr = list(map(int, input().split()))
max_i = -1
max_n = -1
ans = Counter()
for x in arr:
	ans[x] += 1
	if ans[x] > max_n:
		max_i = x
		max_n = ans[x]
print(max_i)


n = input()
has = {}
best = -1
has[best] = -1
ar = [int(x) for x in input().split()]
for x in ar:
	if x not in has:
		has[x] = 1
	else:
		has[x] += 1
	if has[x] > has[best]:
		best = x
print(best)


from collections import Counter
n = int(input())
co = Counter()
ma = 0
ans = 0
for x in map(int, input().split()):
	co[x] += 1
	if co[x] > ma:
		ans = x
		ma = co[x]
print(ans)


n = int(input())
a = list(map(int, input().split()))
likes = {}
for x in a:
	if x not in likes:
		likes[x] = 1
	else:
		likes[x] += 1
max_elem = max(likes.values())
likes.clear()
likes = {}
for x in a:
	if x not in likes:
		likes[x] = 1
	else:
		likes[x] += 1
	if likes[x] == max_elem:
		print(x)
		break


n = int(input())
daf = list(map(int, input().split()))
daf = daf[::-1]
has = dict()
for x in daf:
	if x in has.keys():
		has[x] += 1
	else:
		has[x] = 1
y = max(has.values())
ans = 0
for x in has.keys():
	if has[x] == y:
		ans = x
print(ans)


n = int(input())
l = list(map(int, input().strip().split(' ')))
win = 0
w_likes = 0
d = {}

def winner(x):
	global w_likes
	global win
	if d[x] > w_likes:
		win = x
		w_likes = d[x]
	else:
		pass
for i in range(n):
	if l[i] in d:
		d[l[i]] += 1
		winner(l[i])
	else:
		d.update({l[i]: 1})
		winner(l[i])
print(win)


total_likes = int(input())
max_id = None
max_likes = 0
likes = {}
for i in input().split():
	if not max_id:
		max_id = i
		max_likes = 1
	if i not in likes:
		likes[i] = 1
	else:
		likes[i] += 1
		if likes[i] > max_likes:
			max_likes = likes[i]
			max_id = i
print(max_id)


n = int(input())
k = list(map(int, input().split()))
d = dict.fromkeys(k, 0)
mx = 0
mj = 0
for i in k:
	d[i] += 1
	if d[i] > mx:
		mx = d[i]
		mj = i
print(mj)


n = int(input())
A = list(map(int, input().split()))
Sl = {}
for i in range(n):
	try:
		Sl[A[i]] += 1
	except KeyError:
		Sl[A[i]] = 1
maxim = -1
for i in Sl:
	if Sl[i] > maxim:
		maxim = Sl[i]
Sl = {}
for i in range(n):
	try:
		Sl[A[i]] += 1
	except KeyError:
		Sl[A[i]] = 1
	if Sl[A[i]] == maxim:
		print(A[i])
		break


def count(p):
	return p.count

class Photo:

	def __init__(self, time):
		self.time = time
		self.count = 1
n = int(input())
likes = list(map(int, input().split()))
photos = dict()
for (i, num) in enumerate(likes):
	if num in photos:
		photos[num].count += 1
		photos[num].time = i
	else:
		photos[num] = Photo(i)
best = likes[0]
for i in photos:
	if photos[i].count > photos[best].count:
		best = i
	elif photos[i].count == photos[best].count and photos[i].time < photos[best].time:
		best = i
print(best)


n = int(input())
likes = input().split()
likes = [int(x) for x in likes]
likes.reverse()
maxlike = 0
max = 0
x = []
for i in likes:
	if i not in x:
		x.append(i)
		if likes.count(i) >= max:
			max = likes.count(i)
			maxlike = i
print(maxlike)


import math
import random

def read_ints():
	return [int(x) for x in input(' ').split()]

def main():
	(n,) = read_ints()
	A = [(int(x), i) for (i, x) in enumerate(input(' ').split())]
	A.sort()
	A.append((10 ** 10, n))
	(max_id, max_len, max_last) = (-1, -1, -1)
	(curr_id, curr_len, curr_last) = (-1, -1, -1)
	for (a, i) in A:
		if a == curr_id:
			(curr_len, curr_last) = (curr_len + 1, i)
		else:
			if curr_len >= max_len:
				if curr_len > max_len or curr_last < max_last:
					(max_id, max_len, max_last) = (curr_id, curr_len, curr_last)
			(curr_id, curr_len, curr_last) = (a, 1, i)
	print(max_id)

def __starting_point():
	main()
__starting_point()


arr = []
n = int(input())
like = list(map(int, input().split()))
iden = dict.fromkeys(like, 0)
max = 0
maxind = 0
for item in like:
	iden[item] += 1
	if iden[item] > max:
		max = iden[item]
		maxind = item
print(maxind)


def Voting(n, lis):
	if n == 1:
		return lis[0]
	dic = {}
	val = -999999999999999999999
	ans = 0
	for i in lis:
		if i in dic:
			dic[i] += 1
			if dic[i] > val:
				ans = i
				val = dic[i]
		else:
			dic[i] = 1
			if dic[i] > val:
				ans = i
				val = dic[i]
	return ans
n = int(input())
lis = list(map(int, input().split()))
print(Voting(n, lis))


from collections import Counter
n = int(input())
a = Counter()
result = None
for v in map(int, input().split()):
	a[v] += 1
	if result is None or a[v] > a[result]:
		result = v
print(result)


from collections import defaultdict
from operator import itemgetter
pics = defaultdict(lambda : (0, float('inf')))
input()
for (i, v) in enumerate(map(int, input().split())):
	pics[v] = (pics[v][0] + 1, -i)
print(max(pics.items(), key=itemgetter(1))[0])


(a, b) = (int(input()), list(map(int, input().split())))
(maxValue, mex) = (0, 0)
dt = dict.fromkeys(set(b), 0)
for i in range(a):
	dt[b[i]] += 1
	if dt[b[i]] > maxValue:
		(maxValue, mex) = (dt[b[i]], b[i])
print(mex)


a = int(input())
b = list(map(int, input().split()))
maxi = 0
index = 0
likes = dict()
for i in b:
	if i not in likes:
		likes[i] = 0
	likes[i] += 1
	if likes[i] > maxi:
		maxi = likes[i]
		index = i
print(index)


photos = {}
n = input()
likes = input().split()
m = {'id': 0, 'q': 0}
for p_id in likes:
	if p_id in photos:
		photos[p_id] += 1
	else:
		photos[p_id] = 1
	if photos[p_id] > m['q']:
		m['q'] = photos[p_id]
		m['id'] = p_id
print(m['id'])


n = int(input())
likes_str = input()
likes = likes_str.split()
photo = {}
max_val = 0
max_num = 0
for i in range(0, n):
	photo_num = int(likes[i])
	if photo_num in photo:
		photo[photo_num] += 1
	else:
		photo[photo_num] = 1
	if photo[photo_num] > max_val:
		max_val = photo[photo_num]
		max_num = photo_num
print(max_num)


x = int(input())
lines_string = input()
lines_string = lines_string.split()
lst_tags = []
lst_counts = []
k = 1
for i in range(x):
	if lines_string[i] not in lst_tags:
		lst_tags.append(lines_string[i])
		lines_string[i] = [lines_string[i], 1]
	else:
		for j in range(i - 1, -1, -1):
			if lines_string[j][0] == lines_string[i]:
				lines_string[i] = [lines_string[i], lines_string[j][1] + 1]
				break
p = lines_string[0][0]
for i in range(x):
	if lines_string[i][1] > k:
		k = lines_string[i][1]
		p = lines_string[i][0]
print(p)


n = int(input())
data = map(int, input().split())
d = {}
rec = 0
res = 0
for v in data:
	vv = d.get(v, 0) + 1
	d[v] = vv
	if vv > rec:
		rec = vv
		res = v
print(res)


n = int(input())
a = input().split()
b = []
b.append(1)
winer = int(b[0])
a_winer = a[0]
for i in range(1, len(a)):
	for q in range(i):
		if a[q] == a[i]:
			b[q] += 1
			if b[q] > winer:
				winer = b[q]
				a_winer = a[q]
			b.append(0)
			break
	else:
		b.append(1)
print(a_winer)


from collections import defaultdict
n = int(input())
like_ids = list(map(int, input().split()))
likes_by_id = defaultdict(int)
last_like_position = dict()
for (pos, id) in enumerate(like_ids):
	likes_by_id[id] += 1
	last_like_position[id] = pos
max_likes = max(likes_by_id.values())
best_photos = list(filter(lambda id: likes_by_id[id] == max_likes, likes_by_id.keys()))
fastest_position = min([last_like_position[id] for id in best_photos])
for id in best_photos:
	if last_like_position[id] == fastest_position:
		print(id)
		break
else:
	raise ValueError()


n = int(input())
dic = {}
ar = input().split(' ')
ar = [int(i) for i in ar]
for i in range(n):
	try:
		dic[ar[i]][0] += 1
		dic[ar[i]][1] = i
	except:
		dic[ar[i]] = [1, i]
keys = []
maxi = 0
for i in dic:
	if dic[i][0] > maxi:
		maxi = dic[i][0]
		keys = [i]
	elif dic[i][0] == maxi:
		keys.append(i)
mini = 9999999
id_num = 0
for i in keys:
	if dic[i][1] < mini:
		id_num = i
		mini = dic[i][1]
print(id_num)


n = int(input())
a = list(map(int, input().split()))
m = max([a.count(i) for i in set(a)])
d = {}
for x in a:
	if x in d:
		d[x] += 1
	else:
		d[x] = 1
	if max(d.values()) == m:
		print(x)
		break


n = int(input())
a = list(map(int, input().split()))
(l, h) = (list(set(a)), 0)
f = max(l) * [0]
for i in range(n):
	f[a[i] - 1] += 1
	if f[a[i] - 1] > h:
		h = f[a[i] - 1]
f = None
f = max(l) * [0]
for i in range(n):
	f[a[i] - 1] += 1
	if f[a[i] - 1] == h:
		print(a[i])
		break


from functools import cmp_to_key
n = int(input())
d = {}
a = [int(i) for i in input().split()]
for (i, e) in enumerate(a):
	d[e] = (i + 1, 1, e) if d.get(e) == None else (i + 1, d[e][1] + 1, e)
t1 = sorted(list(d.values()), key=lambda x: x[1])
t2 = list(filter(lambda x: x[1] == t1[-1][1], t1))
t2 = sorted(t2, key=lambda x: x[0])
print(t2[0][-1])


def main():
	n = int(input())
	our = [[0, 0] for i in range(1000001)]
	ask = list(map(int, input().split()))
	for i in range(len(ask)):
		e = ask[i]
		our[e][0] -= 1
		our[e][1] = i
	print(our.index(min(our)))
main()


from collections import Counter
n = int(input())
aa = list(map(int, input().split()))
c = Counter()
best = 0
lead = 1
for a in aa:
	c[a] += 1
	if c[a] > best:
		best = c[a]
		lead = a
print(lead)


import collections
import random
import sys
try:
	from tqdm import tqdm
except:

	def tqdm(iterable):
		return iterable
__taskname = ''
if __taskname:
	sys.stdin = open(__taskname + '.in')
	sys.stdout = open(__taskname + '.out', 'w')
n = int(input())
ans = -1
d = {-1: -1}
for a in map(int, input().split()):
	d[a] = d.get(a, 0) + 1
	if d[a] > d[ans]:
		ans = a
print(ans)


n = int(input())
l = list(map(int, input().split()))
s = [0] * 1000002
ans = (0, 0)
for i in range(n):
	s[l[i]] += 1
	if ans[1] < s[l[i]]:
		ans = (l[i], s[l[i]])
print(ans[0])


num = input()
line = input()
line = line + ' '
temp = ''
dictt = {}
maxx = 0
maxxid = None
for char in line:
	if char == ' ':
		if temp in dictt:
			dictt[temp] = dictt[temp] + 1
		else:
			dictt[temp] = 1
		if dictt[temp] > maxx:
			maxx = dictt[temp]
			maxxid = temp
		temp = ''
	else:
		temp = temp + char
print(maxxid)


n = int(input())
arr = [int(i) for i in input().split()]
prev = 0
c = 0
res = []
for i in sorted(arr):
	if i != prev:
		res.append([c, prev])
		c = 1
		prev = i
	else:
		c += 1
res.append([c, prev])
res.sort(reverse=True)
m = res[0][0]
nres = []
arr.reverse()
for i in res:
	if i[0] == m:
		nres.append([arr.index(i[1]), i[1]])
	else:
		break
nres.sort(reverse=True)
print(nres[0][1])


n = int(input())
a = list(map(int, input().split()))
max_n = 1
cnt = dict()
cnt[a[0]] = 1
max_ = a[0]
for i in range(1, n):
	cur_n = a[i]
	if cur_n not in cnt:
		cnt[cur_n] = 0
	cnt[cur_n] += 1
	if cnt[cur_n] > max_n:
		max_n = cnt[cur_n]
		max_ = cur_n
print(max_)


n = int(input())
a = list(map(int, input().split()))
d = dict()
d[0] = 0
mx = 0
for i in a:
	d[i] = d.get(i, 0) + 1
	if d[i] > d[mx]:
		mx = i
print(mx)


n = int(input())
likes = input().split()
dlike = dict.fromkeys(likes, 0)
liketime = dict.fromkeys(likes, 0)
for i in range(n):
	dlike[likes[i]] += 1
	liketime[likes[i]] = i
mf = max(dlike.values())
m = list()
for i in dlike.keys():
	if dlike[i] == mf:
		m.append(i)
fav = m[0]
for i in m:
	if liketime[i] < liketime[fav]:
		fav = i
print(int(fav))


n = int(input())
a = {}
for i in input().split():
	try:
		if a[i] >= 1:
			b = a.pop(i)
			a[i] = b + 1
	except KeyError:
		a[i] = 1
max = 0
value = 0
for i in a.keys():
	if a[i] > value:
		value = a[i]
		max = i
print(max)


r = m = -1
d = {}
for x in map(int, [*open(0)][1].split()):
	d[x] = d.get(x, 0) + 1
	if d[x] > m:
		m = d[x]
		r = x
print(r)


n = int(input())
data = list(map(int, input().split()))
lst = dict()
tme = dict()
for i in range(n):
	if data[i] in lst.keys():
		lst[data[i]] += 1
	else:
		lst[data[i]] = 1
	tme[data[i]] = i
ps = -1
mx = -1
time = -1
for i in lst.keys():
	if lst[i] > mx:
		mx = lst[i]
		time = tme[i]
		ps = i
	elif lst[i] == mx:
		if time > tme[i]:
			time = tme[i]
			ps = i
print(ps)


n = int(input())
a = list(map(int, input().split()))
likes = dict()
m = [-1, 0]
for num in a:
	if num in likes:
		likes[num] += 1
	else:
		likes[num] = 1
	mnlocal = max(likes, key=lambda q: likes[q])
	mlocal = likes[mnlocal]
	if mlocal > m[1]:
		m = [mnlocal, mlocal]
print(m[0])


count = int(input())
array = input().split()
max_likes = 0
win_number = 0
likes = []
for i in range(count):
	if array[i] not in likes:
		likes.append(array[i])
		likes.append(1)
	if array[i] in likes:
		likes[likes.index(array[i]) + 1] += 1
		if likes[likes.index(array[i]) + 1] > max_likes:
			max_likes = likes[likes.index(array[i]) + 1]
			win_number = array[i]
print(win_number)


n = int(input())
a = map(int, input().split())
s = dict()
ans = -1
pos = 1
for i in a:
	if i in s:
		s[i] += 1
	else:
		s[i] = 1
	if ans < s[i]:
		(pos, ans) = (i, s[i])
print(pos)


n = int(input())
s = input()
arr = s.split(' ')
for i in range(n):
	arr[i] = int(arr[i])
maxx = 0
nom = 0
down = 10001
for i in range(n):
	sch = 0
	for j in range(n):
		if arr[i] == arr[j]:
			end = j
			sch += 1
	if sch >= maxx:
		if end < down and sch > 1 or (sch > maxx and sch > 1):
			nom = arr[i]
			maxx = sch
			down = end
if nom == 0:
	print(arr[0])
else:
	print(nom)


n = int(input())
a = list(map(int, input().split()))
cnt = [0] * (10 ** 6 + 100)
for ai in a:
	cnt[ai] += 1
M = max(cnt)
cnt = [0] * (10 ** 6 + 100)
for ai in a:
	cnt[ai] += 1
	if cnt[ai] == M:
		print(ai)
		exit()


n = int(input())
nums = [int(j) for j in input().split()]
ref = 1000000 * [0]
(winner, max) = (0, 0)
for j in range(n):
	ref[nums[j] - 1] += 1
	if ref[nums[j] - 1] > max:
		(winner, max) = (nums[j], ref[nums[j] - 1])
print(winner)


n = int(input(''))
a = input().split()
d = {0: 0}
rez = 0
for i in range(n):
	a[i] = int(a[i])
	try:
		d[a[i]] += 1
	except KeyError:
		d[a[i]] = 1
	if d[a[i]] > d[rez]:
		rez = a[i]
print(rez)


n = int(input())
likes = [x for x in input().split(' ')]
num_likes = {}
max_likes = -1
max_photo = likes[0]
for p_num in likes:
	if p_num in num_likes:
		num_likes[p_num] = num_likes[p_num] + 1
		if max_likes < num_likes[p_num]:
			max_likes = num_likes[p_num]
			max_photo = p_num
	else:
		num_likes[p_num] = 0
print(max_photo)


n = int(input())
a = list(map(int, input().split()))
likes = dict()
times = dict()
for i in range(len(a)):
	if a[i] not in likes:
		likes[a[i]] = 1
		times[a[i]] = i
	else:
		likes[a[i]] = likes[a[i]] + 1
		times[a[i]] = i
mx = 0
like = []
for i in likes:
	if likes[i] > mx:
		mx = likes[i]
for i in likes:
	if likes[i] == mx:
		like = like + [i]
if len(like) == 1:
	print(like[0])
else:
	slovar = {}
	mn = 10000
	max_like = 0
	for i in range(len(like)):
		slovar[like[i]] = times[like[i]]
	for i in slovar:
		if slovar[i] < mn:
			mn = slovar[i]
			max_like = i
	print(max_like)


from collections import defaultdict
n = input()
likes = defaultdict(int)
maxlikes = 0
idx = 0
for (time, photoid) in enumerate(input().split()):
	likes[photoid] += 1
	if likes[photoid] > maxlikes:
		maxlikes = likes[photoid]
		idx = photoid
print(idx)


from collections import Counter
(n, v, vc, c) = (int(input()), 0, 0, Counter())
for x in map(int, input().split()):
	c[x] += 1
	if c[x] > vc:
		(v, vc) = (x, c[x])
print(v)


n = int(input())
l = list(map(int, input().split()))
ma = 0
d = {}
indx = -1
for i in range(n):
	v = d.get(l[i], 0) + 1
	if ma < v:
		ma = v
		indx = l[i]
	d[l[i]] = v
print(indx)


n = int(input())
id = {}
time_id = {}
if 1 <= n <= 1000:
	string_id = input()
	value = 0
	for i in string_id.split():
		if i in id:
			id[i] += 1
			time_id[i] = value
			value += 1
		else:
			id[i] = 1
			time_id[i] = value
			value += 1
	max = 0
	count = 0
	max_id = []
	for (key, val) in id.items():
		if val > max:
			max = val
	for (key, val) in id.items():
		if val == max:
			max_id.append(key)
			count += 1
	if count == 0:
		[print(key) for (key, val) in id.items() if val == max]
	else:
		min = 10 ** 9
		for (key, val) in time_id.items():
			if key in max_id:
				if val < min:
					min = val
		[print(key) for (key, val) in time_id.items() if val == min]


from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]
c = Counter(a)
k = c.most_common(1)[0][1]
li = []
for (i, j) in c.most_common():
	if j == k:
		li.append(i)
	else:
		break
a.reverse()
print(max(li, key=lambda i: a.index(i)))


from collections import *
n = int(input())
c = Counter()
(a, b) = (0, 0)
for x in map(int, input().split()):
	c[x] += 1
	(a, b) = (c[x], x) if a < c[x] else (a, b)
print(b)


n = input()
a = [int(i) for i in input().split()]
d = {}
max_v = 0
max_k = 0
for i in a:
	if i not in d:
		d[i] = 1
	else:
		d[i] = d[i] + 1
		for (i, j) in d.items():
			if j > max_v:
				max_v = j
				max_k = i
for (i, j) in d.items():
	if j > max_v:
		max_v = j
		max_k = i
print(max_k)


n = input()
(arr, arr1, ptr) = (list(map(int, input().split())), [0] * 1000001, 0)
for i in arr:
	arr1[i] += 1
	if arr1[ptr] < arr1[i]:
		ptr = i
print(ptr)


n = int(input())
d = {}
a = list(map(int, input().split()))
for i in range(n):
	if a[i] not in d:
		d[a[i]] = (1, n - i)
	else:
		d[a[i]] = (d[a[i]][0] + 1, n - i)
print(sorted(d.items(), key=lambda x: x[1])[-1][0])


input()
array_of_images_ids = input().split()
reversed_array_of_images_ids = array_of_images_ids[::-1]
dict_of_likes = {}
for i in set(array_of_images_ids):
	dict_of_likes[i] = array_of_images_ids.count(i)
supposed_id = str(max(dict_of_likes.keys(), key=lambda key: int(dict_of_likes[key])))
max_number = int(dict_of_likes[supposed_id])
supposed_ids = []
for key in dict_of_likes.keys():
	if dict_of_likes[key] >= max_number:
		supposed_ids.append(key)
array_len = len(array_of_images_ids)
position = array_len - reversed_array_of_images_ids.index(supposed_id) - 1
for item in supposed_ids:
	p = array_len - reversed_array_of_images_ids.index(item) - 1
	if p <= position:
		position = p
print(array_of_images_ids[position])


__author__ = 'nadik'
import sys
n = int(input())
a = [int(i) for i in input().split()]
d = {}
for i in range(0, n):
	if a[i] not in d:
		d[a[i]] = (0, -1)
	(likes, time_of_last_like) = d[a[i]]
	d[a[i]] = (likes + 1, i)
(winner, winner_score, winner_time) = (0, -1, n)
for (k, v) in d.items():
	(likes, time_of_last_like) = v
	if likes > winner_score:
		winner = k
		winner_score = likes
		winner_time = time_of_last_like
	elif likes == winner_score:
		if time_of_last_like < winner_time:
			winner = k
			winner_time = time_of_last_like
print(winner)


n = int(input())
a = [*map(int, input().split())]
a.reverse()
d = {}
for i in range(n):
	d[a[i]] = d.get(a[i], 0) + 1
m = max(d.values())
b = []
for i in d.keys():
	if d[i] == m:
		b.append(a.index(i))
b.sort()
print(a[b[-1]])


n = int(input())
a = list(map(int, input().split()))
b = {}
for i in a:
	if not i in b.keys():
		b[i] = 1
	else:
		b[i] += 1
mx = max(b.values())
c = {}
for i in a:
	if not i in c.keys():
		c[i] = 1
	else:
		c[i] += 1
	if c[i] == mx:
		print(i)
		break


n = int(input())
array = list(map(int, input().split(' ')))
like = {}
time = {}
for i in range(n):
	if array[i] in like:
		like[array[i]] += 1
		time[array[i]] = i
	else:
		like.update({array[i]: 1})
		time.update({array[i]: i})
max_likes = max(like.values())
indexes = list()
array = list(set(array))
for a in array:
	if like[a] == max_likes:
		indexes.append(a)
for a in array:
	if a not in indexes:
		time.pop(a)
min_time = min(time.values())
for a in indexes:
	if time[a] == min_time:
		min_time = a
		break
print(min_time)


n = int(input())
a = list(map(int, input().split()))
d = {}
keymax = 0
valuemax = 0
for i in a:
	v = d.get(i, None)
	if v != None:
		d[i] = d[i] + 1
	else:
		d[i] = 1
	if d[i] > valuemax:
		valuemax = d[i]
		keymax = i
print(keymax)


n = int(input())
a = list(map(int, input().split()))
l = [0] * (max(a) + 1)
t = [0] * (max(a) + 1)
for i in range(n):
	l[a[i]] += 1
	t[a[i]] = i
m = max(l)
m1 = 100000000000000000000000
j = 0
for i in range(len(l)):
	if l[i] == m:
		if t[i] < m1:
			m1 = t[i]
			j = i
print(j)


n = int(input())
x = [int(i) for i in input().split()]
data = dict()
for i in range(0, n):
	if not x[i] in data:
		data[x[i]] = [1, i]
	else:
		data[x[i]] = [data[x[i]][0] + 1, i]
t = list(data.items())
t.sort(key=lambda x: (-x[1][0], x[1][1]))
print(t[0][0])


def photos(likes_sum, likes):
	d = {}
	max_value = 0
	last_like = 0
	for like in likes:
		if like in d:
			d[like] += 1
		else:
			d[like] = 1
		if d[like] > max_value:
			max_value = d[like]
			last_like = like
	return last_like
count_likes = int(input())
likes = [int(a) for a in input().split()]
print(photos(count_likes, likes))


n = int(input())
l = list(map(int, input().split()))
h = {}
maxlike = -1
first = 0
for x in l:
	h[x] = h.get(x, 0) + 1
	if h[x] > maxlike:
		maxlike = h[x]
		first = x
print(first)


a = int(input())
l = list(map(int, input().split()))
e = {}
maxx = 0
ans = 1
for i in range(a):
	e[l[i]] = e.get(l[i], 0) + 1
	if e[l[i]] > maxx:
		ans = l[i]
		maxx = e[l[i]]
print(ans)


n = int(input(''))
lst = list(map(int, input().split()))
dic = {}
mostlikes = 0
newlist = []
for item in lst:
	if item not in dic:
		dic[item] = 1
	else:
		dic[item] = dic[item] + 1
for item in dic:
	if dic[item] > mostlikes:
		mostlikes = dic[item]
for item in dic:
	if dic[item] == mostlikes:
		newlist.append(item)
for y in range(len(newlist)):
	for i in range(mostlikes - 1):
		lst.remove(newlist[y])
for item in lst:
	if item in newlist:
		print(item)
		break


n = int(input())
photos = {}
max_count = 0
max_id = 0
ids = [int(x) for x in input().split()]
for i in range(n):
	id = ids[i]
	if id in photos:
		photos[id] += 1
	else:
		photos[id] = 1
	if photos[id] > max_count:
		max_count = photos[id]
		max_id = id
print(max_id)


n = int(input())
l = list(input().split())
s = list(set(l))
x = []
for i in s:
	x.append(l.count(i))
k = max(x)
if x.count(k) == 1:
	print(s[x.index(k)])
else:
	s = list(s)
	y = [0] * len(x)
	for i in l:
		y[s.index(i)] += 1
		if y[s.index(i)] == k:
			print(i)
			break


def main():
	n = int(input())
	(l, m) = ([0] * 1000001, 0)
	for a in map(int, input().split()):
		x = l[a] + 1
		l[a] = x
		if m < x:
			(m, res) = (x, a)
	print(res)
main()


n = int(input())
li = list(map(int, input().split(' ')))
liSort = list(li)
liSort.sort()
counter = 1
listDiffer = []
listDiffer.append(liSort[0])
for i in range(n - 1):
	if liSort[i + 1] > liSort[i]:
		counter += 1
		listDiffer.append(liSort[i + 1])
listCountUnDiffer = []
for i in range(counter):
	listCountUnDiffer.append(li.count(listDiffer[i]))
li.reverse()
maxLikes = max(listCountUnDiffer)
maxIndex = -1
for i in range(counter):
	if listCountUnDiffer[i] == maxLikes:
		if li.index(listDiffer[i]) > maxIndex:
			maxIndex = li.index(listDiffer[i])
			maxIndexZn = li[maxIndex]
print(maxIndexZn)


import string

def is_palindrome(s):
	for i in range(len(s) // 2):
		k = len(s) - 1 - i
		if s[i] != s[k]:
			return False
	return True

def main_function():
	n = int(input())
	max_photos = 0
	who_reached_first = 0
	likes = [int(i) for i in input().split(' ')]
	maxi = max(likes) + 1
	photos = [0 for i in range(maxi)]
	for i in likes:
		photos[i] += 1
		if photos[i] > max_photos:
			max_photos = photos[i]
			who_reached_first = i
	print(who_reached_first)
main_function()


import collections

def main():
	likes_count = int(input())
	likes = input().split()
	id2like_count = collections.defaultdict(int)
	winner_id = None
	for liked_id in likes:
		id2like_count[liked_id] += 1
		if liked_id != winner_id and id2like_count[liked_id] > id2like_count[winner_id]:
			winner_id = liked_id
	print(winner_id)
main()


like_count = int(input())
likes = input().split()
counter = {}
most_liked = ''
max_like_count = 0
for like in likes:
	if like in counter:
		counter[like] += 1
	else:
		counter[like] = 1
	if max_like_count < counter[like]:
		most_liked = like
		max_like_count = counter[like]
print(int(most_liked))


n = int(input())
inp = list(map(int, input().split()))
a = [0] * 1000100
b = inp[::-1]
s = set()
maxx = 0
for i in inp:
	s.add(i)
	a[i] += 1
	maxx = max(a[i], maxx)
t = 0
for i in s:
	if a[i] == maxx:
		t = max(t, b.index(i))
print(b[t])


n = int(input())
a = map(int, input().split())
likes = {}
for (i, like) in enumerate(a):
	if not like in likes:
		likes[like] = [1, i]
	else:
		likes[like][0] += 1
		likes[like][1] = i
likes = list(likes.items())
likes.sort(key=lambda x: x[1][0] * 10000 - x[1][1])
print(likes[-1][0])


n = int(input())
like = list(map(int, input().split()))
id = 0
A = [0] * 1000005
for i in range(n):
	A[like[i]] += 1
	if A[like[i]] > A[id]:
		id = like[i]
print(id)


n = int(input())
foto = [int(i) for i in input().split()]
rat = {}
max_like = [0, 0]
for i in foto:
	if rat.get(i):
		rat[i] += 1
	else:
		rat.update({i: 1})
	if rat[i] > max_like[0]:
		max_like[0] = rat[i]
		max_like[1] = i
print(max_like[1])


n = int(input())
data = [int(i) for i in input().split()]
dct = {}
keys = []
mx = 0
ret = 0
for box in data:
	if box in keys:
		dct[box] += 1
	else:
		dct[box] = 1
		keys.append(box)
	if dct[box] > mx:
		mx = dct[box]
		ret = box
print(ret)


n = int(input())
l = list(map(int, input().split()))
d1 = dict()
d = dict()
s = set()
s1 = set()
for i in l:
	if i in s:
		d[i] += 1
	else:
		d[i] = 1
	s.add(i)
max1 = 0
for i in d:
	max1 = max(max1, d[i])
for i in l:
	if i in s1:
		d1[i] += 1
	else:
		d1[i] = 1
	s1.add(i)
	if d1[i] == max1:
		print(i)
		break


numbers = int(input())
line = input()
dic = {}
parts = line.split(' ')
maxi = parts[0]
for x in parts:
	if x in dic.keys():
		dic[x] += 1
	else:
		dic[x] = 1
	if dic[x] > dic[maxi]:
		maxi = x
print(maxi)


def mp():
	return map(int, input().split())

def lt():
	return list(map(int, input().split()))

def pt(x):
	print(x)

def ip():
	return input()

def it():
	return int(input())

def sl(x):
	return [t for t in x]

def spl(x):
	return x.split()

def aj(liste, item):
	liste.append(item)

def bin(x):
	return '{0:b}'.format(x)
n = it()
L = lt()
E = []
for i in set(L):
	E.append([i, L.count(i)])
E.sort(key=lambda x: x[1], reverse=True)
R = [E[0][0]]
index = 1
while index < len(E) and E[index][1] == E[0][1]:
	R.append(E[index][0])
	index += 1
L = L[::-1]
R.sort(key=lambda x: L.index(x), reverse=True)
print(R[0])


n = int(input())
a = {}
arr = input().split(' ')
likes = [int(x) for x in arr]
maximum = 0
maximum_el = 0
for i in likes:
	if a.get(i):
		a[i] += 1
		if a[i] > maximum:
			maximum = a[i]
			maximum_el = i
	else:
		a[i] = 1
		if a[i] > maximum:
			maximum = a[i]
			maximum_el = i
print(maximum_el)


from collections import Counter
n = int(input())
a = [int(i) for i in input().split(' ')]
c = Counter()
mx = -1
mxid = -1
for i in range(n):
	c[a[i]] += 1
	if c[a[i]] > mx:
		mx = c[a[i]]
		mxid = a[i]
print(mxid)


n = int(input())
votes = list(map(int, input().split(' ')))
checked = []
popular = []
vote_count = {}
for v in votes:
	if v not in checked:
		checked.append(v)
		vote_count[v] = votes.count(v)
mxval = -1
mx = -1
for key in vote_count.keys():
	if vote_count[key] > mxval:
		mxval = vote_count[key]
		mx = key
popular.append(mx)
for key in vote_count.keys():
	if key != mx and vote_count[key] == vote_count[mx]:
		popular.append(key)
last = -1
occured = []
if len(popular) == 1:
	print(popular[0])
else:
	j = n - 1
	while j >= 0:
		if votes[j] in popular and votes[j] not in occured:
			occured.append(votes[j])
		j -= 1
	print(occured[-1])


n = int(input())
likes = list(map(int, input().split(' ')))
max_likes = 0
max_likes_pid = -1
lc = {}
for pid in likes:
	lc[pid] = lc.get(pid, 0) + 1
	if lc[pid] > max_likes:
		max_likes = lc[pid]
		max_likes_pid = pid
print(max_likes_pid)


n = int(input())
a = list(map(int, input().split()))
b = [[], []]
maxl = -1
for i in range(len(a)):
	photo = a[i]
	if b[0].count(photo) == 0:
		b[0].append(photo)
		b[1].append(0)
		nom = b[0].index(photo)
	nom = b[0].index(photo)
	b[1][nom] += 1
	maxmom = max(b[1])
	if maxl < maxmom:
		maxl = maxmom
		mesto = b[1].index(maxmom)
		ans = b[0][mesto]
print(ans)


n = int(input())
a = list(map(int, input().split(' ')))
d = dict()
for (i, x) in enumerate(a):
	if not x in d:
		d.setdefault(x, (1, i))
	else:
		d[x] = (d[x][0] + 1, i)
keyRes = -1
res = (-1, -1)
for (key, val) in d.items():
	if val[0] > res[0] or (val[0] == res[0] and val[1] < res[1]):
		res = val
		keyRes = key
print(keyRes)


n = int(input())
a = [0] * 1000001
m = 0
l = list(map(int, input().split()))
for i in range(n):
	a[l[i]] += 1
	if a[l[i]] > m:
		m = a[l[i]]
		j = l[i]
print(j)


n = int(input())
arr = [int(x) for x in input().split()]
m = -1
ans = -1
d = dict()
for i in arr:
	if i in d:
		d[i] += 1
	else:
		d[i] = 1
	if m == -1 or d[i] > m:
		m = d[i]
		ans = i
print(ans)


n = int(input())
a = list(map(int, input().split()))
c = {el: 0 for el in set(a)}
m = 0
ans = -1
for el in a:
	c[el] += 1
	if c[el] > m:
		m = c[el]
		ans = el
print(ans)


n = int(input())
line = input().split()
maxi = line[0]
mas = {}
mas[maxi] = 1
for i in range(1, n):
	a = line[i]
	if not a in mas:
		mas[a] = 1
	else:
		mas[a] += 1
	if mas[a] > mas[maxi]:
		maxi = a
print(maxi)


num = input()
likes = input()
likes_lst = likes.split(' ')
iden_lst = []
num_lst = []
max_num = 0
max_iden = -1
for item in likes_lst:
	if not int(item) in iden_lst:
		iden_lst.append(int(item))
		num_lst.append(1)
		pos = len(iden_lst) - 1
		if num_lst[pos] > max_num:
			max_num = num_lst[pos]
			max_iden = iden_lst[pos]
	else:
		pos = iden_lst.index(int(item))
		num_lst[pos] += 1
		if num_lst[pos] > max_num:
			max_num = num_lst[pos]
			max_iden = iden_lst[pos]
print(max_iden)


kek = int(input())
a = [int(i) for i in input().split()]
z = dict()
z[10 ** 10] = 0
q = 10 ** 10
for i in a:
	if not i in z:
		z[i] = 0
	z[i] += 1
	if z[i] > z[q]:
		q = i
print(q)


N = int(input())
(likes, D, mx, ans) = (list(map(int, input().split())), {}, 0, -1)
for num in likes:
	D[num] = D.get(num, 0) + 1
	if D[num] > mx:
		mx = D[num]
		ans = num
print(ans)


n = int(input())
A = [0] * 1000001
idx = 1
a = list(map(int, input().split()))
for i in a:
	A[i] += 1
	if A[i] > A[idx]:
		idx = i
print(idx)


n = int(input())
a = list(map(int, input().split()))
d = {}
ans = a[0]
count = 1
for i in range(n):
	if a[i] not in d:
		d[a[i]] = 1
	else:
		d[a[i]] += 1
		if a[i] == ans:
			count += 1
		elif d[a[i]] > count:
			ans = a[i]
			count = d[a[i]]
print(ans)


n = int(input())
arr = list(map(int, input().split()))
cnt = 0
val = -1
d = {}
for i in arr:
	if i in d:
		d[i] += 1
	else:
		d[i] = 1
	if d[i] > cnt:
		cnt = d[i]
		val = i
print(val)


n = int(input())
d = dict()
s = input().split()
m = 0
a = -1
for i in s:
	if i in d:
		d[i] += 1
		if m < d[i]:
			m = d[i]
			a = i
	else:
		d[i] = 1
		if m < d[i]:
			m = d[i]
			a = i
print(a)


from collections import Counter
n = int(input())
max = -1
max_photo_id = -1
photo_likes = Counter()
ids_str = input().split()
for i in range(n):
	photo_id = int(ids_str[i])
	photo_likes[photo_id] += 1
	if photo_likes[photo_id] > max:
		max = photo_likes[photo_id]
		max_photo_id = photo_id
print(max_photo_id)


likes = input()
ids = input().split(' ')
dict = {}
for id in ids:
	if not id in dict:
		dict[id] = 1
	else:
		dict[id] += 1
max_ = sorted(list(dict.values()))[len(dict) - 1]
max_count = len(list(filter(lambda x: x == max_, list(dict.values()))))
not_first = list()
for i in range(len(ids)):
	if dict[ids[-i - 1]] == max_ and (not ids[-i - 1] in not_first) and (max_count > 1):
		max_count -= 1
		not_first.append(ids[-i - 1])
	if dict[ids[-i - 1]] == max_ and max_count < 2 and (not ids[-i - 1] in not_first):
		print(ids[-i - 1])
		break


read = lambda : map(int, input().split())
n = int(input())
a = list(read())
from collections import Counter
c = Counter()
(Max, ans) = (0, 0)
for i in a:
	c[i] += 1
	if c[i] > Max:
		Max = c[i]
		ans = i
print(ans)


n = int(input())
a = input().split()
b = set(a)
maximum = -1
maximum_id = []
for i in b:
	x = a.count(i)
	if x > maximum:
		maximum_id = [int(i)]
		maximum = x
	elif x == maximum:
		maximum_id.append(int(i))
a = a[::-1]
maximum = -1
answer = -1
for i in maximum_id:
	x = a.index(str(i))
	if x > maximum:
		answer = i
		maximum = x
print(answer)


n = eval(input())
arr = {}
max = 0
mass = input().split()
for k in mass:
	if k in arr:
		arr[k] += 1
	else:
		arr[k] = 1
	if max < arr[k]:
		max = arr[k]
		liker = k
print(liker)


total = input()
timeline = input().split()
photos = len(set(timeline))
numberOfLikes = dict.fromkeys(timeline, 0)
max = -1
for pic in timeline:
	numberOfLikes[pic] += 1
	if numberOfLikes[pic] > max:
		max = numberOfLikes[pic]
		res = pic
print(res)


from functools import reduce
a = int(input())
b = list([int(m) for m in input().split(' ')])
m = max([len(list([m for m in b if m == i])) for i in b])
v = {a: 0 for a in b}
for i in b:
	v[i] += 1
	if v[i] == m:
		print(i)
		return


n = int(input())
s = input().split()
d = dict()
for i in range(len(s)):
	key = s[i]
	d[key] = s.count(key)
max_count = max(d.values())
l = []
for i in range(len(s) - 1, -1, -1):
	key = s[i]
	if s.count(key) == max_count and key not in l:
		l.append(s[i])
print(l[len(l) - 1])


n = int(input())
a = list(map(int, input().split()))
d = dict()
for i in range(n):
	if a[i] not in d:
		d[a[i]] = (1, -i)
	else:
		d[a[i]] = (d[a[i]][0] + 1, -i)
print(max(d.keys(), key=lambda x: d[x]))


I = input
L = list
C = L.count
D = L.index
I()
a = L(map(int, I().split()))[::-1]
r = a[0]
for x in set(a):
	if C(a, x) > C(a, r) or (C(a, x) == C(a, r) and D(a, x) > D(a, r)):
		r = x
print(r)


n = int(input())
likes = input()
list_of_likes = []
list_of_likes = likes.split()
dict_of_likes = {}
maximum = 0
iden = None
for i in range(n):
	if dict_of_likes.get(list_of_likes[i]) == None:
		dict_of_likes[list_of_likes[i]] = 1
		if maximum < 1:
			maximum = 1
			iden = list_of_likes[i]
	else:
		dict_of_likes[list_of_likes[i]] = dict_of_likes[list_of_likes[i]] + 1
		if dict_of_likes[list_of_likes[i]] > maximum:
			maximum = dict_of_likes[list_of_likes[i]]
			iden = list_of_likes[i]
print(iden)


from collections import defaultdict

def solve():
	n = int(input())
	A = [int(x) for x in input().split()]
	D = defaultdict(int)
	(M, argmax) = (0, None)
	for a in A:
		D[a] += 1
		if M < D[a]:
			M = D[a]
			argmax = a
	return argmax
print(solve())


n = int(input())
a = list(map(int, input().split()))
p = {}
for i in range(n):
	if a[i] in p:
		p[a[i]] += 1
	else:
		p[a[i]] = 1
b = max((p[i] for i in p))
for i in p:
	p[i] = 0
for i in a:
	p[i] += 1
	if p[i] == b:
		print(i)
		exit(0)


n = input()
(a, b) = ([0] * 11 ** 6, 0)
for x in map(int, input().split()):
	a[x] += 1
	b = x if a[b] < a[x] else b
print(b)


n = int(input())
ai = list(map(int, input().split()))
photos = [[0] * 1000000 for i in range(2)]
for i in range(n):
	photos[0][ai[i] - 1] += 1
	photos[1][ai[i] - 1] = i
max_likes = max(photos[0])
min_ind = 1000000
ans = 0
for i in range(1000000):
	if photos[0][i] != 0 and max_likes == photos[0][i]:
		if min_ind > photos[1][i]:
			min_ind = photos[1][i]
			ans = i + 1
print(ans)


from collections import defaultdict
n = int(input())
p = defaultdict(lambda : [0, 0])
aa = list(map(int, input().split()))
for i in range(n):
	a = aa[i]
	p[a][0] += 1
	p[a][1] = i
print(max(p.keys(), key=lambda a: (p[a][0], -p[a][1])))


(n, d, k, m) = (int(input()), {}, None, 0)
for i in input().split():
	if i in d:
		d[i] += 1
	else:
		d[i] = 1
	if d[i] > m:
		m = d[i]
		k = i
print(k)


input()
(s, p, k) = ({}, '', 0)
for q in input().split():
	s[q] = s.get(q, 0) + 1
	if s[q] > k:
		(p, k) = (q, k + 1)
print(p)


n = int(input())
v = [int(i) for i in input().split()]
mapa = {}
ma = 0
res = -1
for i in v:
	if i not in mapa:
		mapa[i] = 0
	mapa[i] += 1
	if mapa[i] > ma:
		ma = mapa[i]
		res = i
print(res)


n = int(input())
s = input().split()
x = []
y = list(reversed(s))
z = 0
pd = 0
for j in range(0, n):
	if y[j] not in x:
		x.append(y[j])
x = list(reversed(x))
for i in range(0, len(x)):
	if s.count(x[i]) > z:
		z = s.count(x[i])
		pd = x[i]
print(pd)


n = int(input())
a = list(map(int, input().split()))
ans = -1
d = {}
for ind in a:
	if d.get(ind) != None:
		d[ind] += 1
	else:
		d[ind] = 0
	if ans == -1 or d[ind] > d[ans]:
		ans = ind
print(ans)


n = int(input())
a = list(map(int, input().split()))
max_count = 0
ans = 0
for i in range(n):
	if a[:i + 1].count(a[i]) > max_count:
		max_count = a[:i + 1].count(a[i])
		ans = a[i]
print(ans)


n = int(input())
a = [int(i) for i in input().split()]
d = set(a)
l = []
f = {}
for i in d:
	l.append(a.count(i))
e = max(l)
q = l.count(e)
if q == 1:
	for j in d:
		if a.count(j) == e:
			print(j)
else:
	for j in range(0, len(a)):
		if a[j] not in f:
			f[a[j]] = 1
		else:
			f[a[j]] = f[a[j]] + 1
		if f[a[j]] == e:
			print(a[j])
			break


n = int(input())
s = [i for i in input().split()]
a = {s[i]: 0 for i in range(n)}
b = a.copy()
c = 0
for i in range(n):
	a[s[i]] += 1
maxi = max((a[i] for i in a))
for i in range(n):
	if a[s[i]] == maxi:
		if b[s[i]] == maxi - 1:
			c = s[i]
			break
		else:
			b[s[i]] += 1
print(c)


__author__ = 'Alexandret'
likes_amount = int(input())
photo_rating = dict()
likes = input().split(' ')
current_chemp = -1
current_chemp_res = -1
for photo_id in likes:
	if photo_id in photo_rating:
		photo_rating[photo_id] += 1
	else:
		photo_rating[photo_id] = 1
	if photo_rating[photo_id] > current_chemp_res:
		current_chemp = photo_id
		current_chemp_res = photo_rating[photo_id]
print(current_chemp)


n = int(input())
s = [int(z) for z in input().split()]
D = {}
M = s[0]
Mc = 1
for i in s:
	if i in D:
		D[i] += 1
		if i == M:
			Mc += 1
		elif D[i] > Mc:
			M = i
			Mc = D[i]
	else:
		D[i] = 1
print(M)


n = int(input())
largest = 0
votes = list(map(int, input().split()))
numberofvotes = [0] * 1000000
for x in range(n):
	numberofvotes[votes[x] - 1] += 1
	if numberofvotes[votes[x] - 1] > largest:
		largest = numberofvotes[votes[x] - 1]
		winner = votes[x]
print(winner)


def main():
	n = int(input())
	arr = [int(x) for x in input().split()]
	d = [0] * (10 ** 6 + 1)
	for x in arr:
		d[x] += 1
	m = max(d)
	d = [0] * (10 ** 6 + 1)
	for x in arr:
		d[x] += 1
		if d[x] == m:
			print(x)
			return
main()


n = int(input())
photos = {}
best_photo = 0
max_likes = 0
q = list(map(int, input().split()))
for id in q:
	try:
		photos[id] += 1
	except KeyError:
		photos[id] = 1
	if photos[id] > max_likes:
		best_photo = id
		max_likes = photos[id]
print(best_photo)


a = int(input())
b = list(map(int, input().split()))
d = []
e = []
c = 0
for x in b:
	if b.count(x) > c:
		c = b.count(x)
for x in b:
	if b.count(x) == c:
		d.append(x)
for x in range(len(d)):
	a = 0
	if d.count(d[a]) != 1:
		d.pop(d.index(d[a]))
	else:
		a += 1
print(d[0])


n = int(input())
a = [int(x) for x in input().split()]
score = dict()
(sup, winner) = (-2 ** 31, None)
for v in a:
	score[v] = score[v] + 1 if v in score else 1
	if score[v] > sup:
		(sup, winner) = (score[v], v)
print(winner)


n = int(input())
A = input().split()
max = 0
max_i = A[0]
Likes = dict()
for a in A:
	if a not in Likes:
		Likes[a] = 1
	else:
		Likes[a] += 1
		if Likes.get(a) > max:
			max = Likes.get(a)
			max_i = int(a)
print(max_i)


from collections import *
n = int(input())
c = Counter()
ans = []
for (i, x) in enumerate(map(int, input().split())):
	c[x] += 1
	ans += [(c[x], -i, x)]
print(max(ans)[2])


n = int(input())
a = list(map(int, input().split()))
b = [0 for i in range(1000001)]
m = 0
f = 0
for i in range(n):
	k = a[i]
	b[k] += 1
	if b[k] > m:
		m = b[k]
		f = k
print(f)


def solve(photo_ids):
	freq = dict()
	winner_id = None
	winner_freq = None
	for photo_id in photo_ids:
		if photo_id not in freq:
			freq[photo_id] = 0
		freq[photo_id] += 1
		if winner_freq is None or freq[photo_id] > winner_freq:
			winner_freq = freq[photo_id]
			winner_id = photo_id
	return winner_id

def main():
	n = int(input())
	photo_ids = [int(i) for i in input().split()]
	print(solve(photo_ids))
main()


likes = int(input())
mas = input().split()
d = {}
for i in mas:
	if i in d:
		d[i] += 1
	else:
		d[i] = 1
maxx = max(d.values())
res = 0
for i in range(likes - 1, -1, -1):
	k = mas[i]
	if d[mas[i]] == maxx:
		res = mas[i]
		d[mas[i]] = 0
print(res)


n = int(input())
maxvoted = 0
ind = 0
mydict = dict()
s = input().split()
for i in s:
	if i not in mydict:
		mydict[i] = 1
		if maxvoted == 0:
			maxvoted = 1
			ind = i
	else:
		mydict[i] += 1
		if mydict[i] > maxvoted:
			ind = i
			maxvoted = mydict[i]
print(ind)


n = int(input())
l = [int(i) for i in input().split()]
maxi = -1
cnt = [0] * (10 ** 6 + 9)
for i in l:
	cnt[i] += 1
	if cnt[i] > maxi:
		maxi = cnt[i]
		ans = i
print(ans)


likes_num = int(input())
likes = dict()
time = 0
for i in input().split():
	if i in likes:
		likes[i][0] += 1
		likes[i][1] = time
	else:
		likes[i] = [1, time]
	time += 1
max_likes = 0
for (key, value) in likes.items():
	if value[0] > max_likes:
		max_likes = value[0]
		res = key
	elif value[0] == max_likes and likes[res][1] > value[1]:
		res = key
print(res)


n = int(input())
a = list(map(int, input().split(' ')))
c = {}
for i in range(n):
	if a[i] not in c:
		c[a[i]] = [0, 0, a[i]]
	c[a[i]][0] -= 1
	c[a[i]][1] = i
print(sorted(c.values())[0][-1])


a = [0] * (10 ** 3 + 1)
n = int(input())
a = [int(i) for i in input().split()]
m = max([a.count(i) for i in a])
b = {}
for i in a:
	b[i] = 0
for i in a:
	b[i] += 1
	for (key, val) in b.items():
		if val == m:
			print(key)
			exit()


n = int(input())
a = list(map(int, input().split()))
count = {}
for x in a:
	count[x] = count.get(x, 0) + 1
candidates = [key for key in count if count[key] == max(count.values())]
for x in a[::-1]:
	if x in candidates:
		if len(candidates) == 1:
			print(x)
			break
		else:
			candidates.remove(x)


a = int(input())
t = list(map(int, input().split()))
s = set(t)
ct = []
inde = []
for j in s:
	ct.append(t.count(j))
	inde.append(j)
if ct.count(max(ct)) > 1:
	y = 0
	for b in s:
		if t[::-1].index(b) > y and t.count(b) == max(ct):
			y = t[::-1].index(b)
	print(t[::-1][y])
else:
	print(inde[ct.index(max(ct))])


n = int(input())
m = list(map(int, input().split()))
b = {}
for i in range(n):
	s = m[i]
	if s in b:
		b[s][1] = i
		b[s][0] += 1
	else:
		b[s] = [1, i]
top = max((b[k][0] for k in b))
f = sorted([n for n in b if b[n][0] == top], key=lambda k: b[k][1])
print(f[0])


n = int(input())
a = [0] * (10 ** 6 + 1)
best = 0
for i in map(int, input().split(' ')):
	a[i] += 1
	if a[i] > a[best]:
		best = i
print(best)


likes = input()
photos = input()
photos = photos.split()

def main(photos, likes):
	count = {}
	new_count = {}
	for i in photos:
		if i in count:
			count[i] += 1
		else:
			count[i] = 1
	value = max(count.values())
	for i in photos:
		if i in new_count:
			new_count[i] += 1
		else:
			new_count[i] = 1
		if new_count[i] == value:
			return i
print(main(photos, likes))


n = int(input())
likes = input().split()
photos = dict()
best = int(likes[0])
for like in likes:
	like = int(like)
	if like not in photos:
		photos[like] = 0
	photos[like] += 1
	if photos[best] < photos[like]:
		best = like
print(best)


l = int(input())
arr = list(map(int, input().split()))
hash = {}
mxm = 0
max_sum = 0
for i in arr:
	if i not in hash.keys():
		hash[i] = 1
	else:
		hash[i] += 1
	if hash[i] > max_sum:
		mxm = i
		max_sum = hash[i]
print(mxm)


n = int(input())
a = input().split()
if len(a) == n:
	ids = {}
	max = 0
	for el in a:
		if ids.get(el) == None:
			ids[el] = 1
		else:
			ids[el] = 1 + ids.get(el)
		if ids.get(el) > max:
			max = ids.get(el)
			answer = el
	print(answer)