n = int(input()) cnt = {} for x in map(int,input().split()): if x not in cnt: cnt[x] = 0 cnt[x] += 1 a = list(cnt.items()) a.sort(key = lambda item: (-item[1],item[0])) for k,v in a: print(k,v)