N = int(input()) As = set() for _ in range(N): A = input() if ' ' in A: print('assert') break A = int(A) if len(As) < 3: As.add(A) else: for i in range(len(As)): if As[i] < A: As.insert(i, A) As.pop() else: As = sorted(list(As), reverse=True) if len(As) < 2: print(As[len(As) - 1] * 2) else: print(As[0] + As[2])