def solution(N, stages):
stages.sort()
s = list(set(stages))
k = {i:0 for i in range(1,N+1)}
for i in s:
if i > N:
pass
else:
idx = stages.index(i)
k[stages[idx]]=(stages.count(stages[idx])/len(stages[idx:]))
ans = list(k.items()) #list(k.values)
ans.sort(key=lambda x:(-x[1],x[0]))
answer = [a[0] for a in ans]
return answer