class BIT(): def __init__(self,N): self.N = N self.bit = [0] * (N + 1) def sum(self,loc): loc -= 1 res = 0 while loc: res += self.bit[loc] loc -= loc & -loc return res def sum_range(self,x,y): return self.sum(y) - self.sum(x - 1) def add(self, loc, x): while loc <= self.N: self.bit[loc] += x loc += loc & -loc def update(self,loc,x): while loc <= self.N: self.bit[loc] = x loc +=loc & -loc def binary_search(self,x): upper = self.N - 1 lower = 0 while upper - lower>1: mid = ( upper + lower) // 2 if self.sum(mid) > x - 1: upper = mid else: lower = mid return lower + 1 mod = 10 ** 9 + 7 N = int(input()) A = list(map(int, input().split())) A.sort() Bit = BIT(3 * 10 ** 5) ans = 0 large = 0 for i in range(N)[::-1]: ans += (N - 1 - i) * A[i] ans -= large for j in range(A[i],3 * 10 ** 5, A[i]): ans += A[i] * ((N - 1 - i) - Bit.sum(j)) Bit.add(A[i], 1) large += A[i] ans %= mod large %= mod print(ans)