class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): i += 1 s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def sumrange(self, i, j): si = self.sum(i - 1) sj = self.sum(j) return sj - si def add(self, i, x): i += 1 while i <= self.size: self.tree[i] += x i += i & -i def lower_bound(self, w): if w <= 0: return 0 x = 0 r = 1 << (self.size).bit_length() while r > 0: if x+r < self.size and self.tree[x+r] < w: w -= self.tree[x+r] x += r r = r >> 1 return x N = int(input()) A = list(map(int, input().split())) A.sort(reverse=True) M = int(A[0]**0.5) bit = Bit(A[0]+2) ans = 0 for i, a in enumerate(A): ans += (2*i-N+1)*a if a >= M: v = 0 for j in range(M+2): if a*j > A[0]: break ans += j*bit.sumrange(j*a, min((j+1)*a-1, A[0]))*a else: for b in A[:i]: ans += b//a*a bit.add(a, 1) print(ans)