import java.io.PrintWriter import java.util.* import kotlin.math.* // sum of A_j * (A_i / A_j) fun helper(a: Array): Long { val n = a.size val max = a.maxOrNull()!! val sqrt = sqrt(max.toDouble()).roundToInt() val l = Array(sqrt) { 0L } val bit = BIT(max + 1) var ans = 0L for (i in 0 until n) { if (a[i] < sqrt) { ans += l[a[i]] } else { for (k in 0..max step a[i]) { ans += k * bit.sum(k until minOf(k + a[i], max + 1)) } } bit.add(a[i], 1) for (j in 1 until sqrt) { l[j] += a[i] / j * j.toLong() } } return ans } fun PrintWriter.solve() { val n = nextInt() val a = Array(n) { nextInt() } a.sortDescending() var ans = helper(a) for (i in 0 until n) { ans += (2 * i - n + 1L) * a[i] } println(ans) } class BIT(private val n: Int) { private val data = LongArray(n) { 0 } fun add(i: Int, x: Long) { var p = i + 1 while (p <= n) { data[p - 1] += x p += p and -p } } fun sum(range: IntRange): Long { val l = range.first val r = range.last + 1 return sum(r) - sum(l) } private fun sum(i: Int): Long { var r = i var s = 0L while(r > 0) { s += data[r - 1] r -= r and -r } return s } } fun main() { val writer = PrintWriter(System.out, false) writer.solve() writer.flush() } // region Scanner private var st = StringTokenizer("") private val br = System.`in`.bufferedReader() fun next(): String { while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine()) return st.nextToken() } fun nextInt() = next().toInt() fun nextLong() = next().toLong() fun nextLine() = br.readLine() fun nextDouble() = next().toDouble() // endregion