n = read_line.to_i a = read_line.split.map(&.to_i64).sort max = a.max sum = Array.new(max * 3 + 1, 0i64) cnt = Array.new(max * 3 + 1, 0i64) ans = 0i64 n.times do |i| v = a[i] sum[v] = v cnt[v] = 1 ans += v * (n - 1 - i) end 1.upto(sum.size - 1) do |i| sum[i] += sum[i - 1] cnt[i] += cnt[i - 1] end a.each do |v| cur = v while cur <= max + v s = sum[cur + v - 1] - sum[cur] c = cnt[cur + v - 1] - cnt[cur] ans -= s - c * cur cur += v end end puts ans