#!/bin/python3 import sys def maximumPeople(p, x, y, r): # Return the maximum number of people that will be in a sunny town after removing exactly one cloud. n=len(p) li=[] hs=[] cl=[] s=0 for i in range(m): li.append((y[i]-r[i],y[i]+r[i])) for j in range(len(x)): t=x[j] k=0 for h in range(len(li)): if t>=li[h][0] and t<=li[h][1]: k=1 hs.append(1); break if k==0: s=s+p[j] hs.append(0) for z in range(len(hs)): if(hs[z]==1): cl.append(p[z]) if len(cl)==1: s=s+cl[0] return s g=max(cl) ind=cl.index(g) del cl[ind] for i in cl: s=s+i return s if __name__ == "__main__": n = int(input().strip()) p = list(map(int, input().strip().split(' ')))#people x = list(map(int, input().strip().split(' ')))#house m = int(input().strip())#clouds y = list(map(int, input().strip().split(' ')))#yi r = list(map(int, input().strip().split(' ')))#ri result = maximumPeople(p, x, y, r) print(result)