def min2(x,y): return x if x < y else y import sys input = sys.stdin.readline N=int(input()) A=list(map(int, input().split())) A.sort() M=max(A) S=[0]*(M+1) for a in A: S[a]+=1 C=[0] for a in S: C.append(C[-1]+a) res=N*sum(A) for i in range(N): l,r=0,A[i]-1 k=0 while l+A[i]<=M: l+=A[i] r+=A[i] k+=1 res-=(C[min2(r+1,M+1)]-C[l])*k*A[i] print(res)