n=int(input()) L=list(map(int,input().split())) a=0 while sum(L)>0: i=L.index(max(L)) a+=L[i] L[i]=0 if i>0:L[i-1]=0 if i