import bisect def main(): import sys input = sys.stdin.read data = input().split() N = int(data[0]) A = list(map(int, data[1:N+1])) A.sort() prefix = [0] * (N + 1) for i in range(N): prefix[i+1] = prefix[i] + A[i] max_A = A[-1] total = 0 for i in range(N): s = A[i] idx = bisect.bisect_right(A, s) count_l = N - idx sum_l = prefix[N] - prefix[idx] K = 0 k = 1 while True: low = k * s if low > max_A: break high = (k + 1) * s - 1 if k == 1: new_low = s + 1 else: new_low = low high_adj = min(high, max_A) if new_low > high_adj: k += 1 continue left = bisect.bisect_left(A, new_low) right = bisect.bisect_right(A, high_adj) count = right - left K += k * count if high_adj == max_A: break k += 1 contribution = s * (count_l + K) - sum_l total += contribution print(total) if __name__ == "__main__": main()