n=int(input())
tip=[]
for _ in range(n):
tip.append(int(input()))
tip.sort()
ans1, ans2, cnt=0, 0, 1
for i in range(n):
temp=tip[i]-(cnt-1)
if temp<=0:
continue
else:
cnt+=1
ans1+=temp
tip.sort(reverse=True)
cnt=1
for i in range(n):
temp=tip[i]-(cnt-1)
if temp<=0:
continue
else:
cnt+=1
ans2+=temp
print(max(ans1, ans2))
< 수정 >
n=int(input())
tip=[]
for _ in range(n):
tip.append(int(input()))
ans, cnt=0, 1
tip.sort(reverse=True)
for i in range(n):
temp=tip[i]-(cnt-1)
if temp<=0:
continue
else:
cnt+=1
ans+=temp
print(ans)