#include using namespace std; #include using namespace atcoder; using ll = long long; using vi = vector; using vvi = vector>; using pii = pair; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define repr(i, n) for (int i = (int)(n - 1); i >= 0; --i) int main() { int n; cin >> n; vi a(n); rep(i, n) cin >> a[i]; sort(a.begin(), a.end(), greater()); int L = a[0] + 1; ll ret = 0; ll s = 0; fenwick_tree fw(L); rep(i, n) { ret += (ll)a[i] * i; ret -= s; for (int q = 1; a[i] * q < L; q++) { int c = fw.sum(a[i] * q, min(L, a[i] * (q + 1))); ret += (ll)a[i] * q * c; } s += a[i]; fw.add(a[i], 1); } cout << ret << endl; return 0; }