#include using namespace std; // Template // ============================================== // pbds // #include // #include // using namespace __gnu_pbds; // template> // using ordered_set = tree; // Debugging #ifdef LOCAL #include "debug.h" #else #define debug(...) #define see(x) #endif typedef long long ll; typedef vector VI; typedef vector VLL; typedef vector VB; typedef vector> VVI; typedef pair PI; typedef pair PLL; typedef vector> VPI; #define pb push_back #define ff first #define ss second #define mp make_pair #define all(a) a.begin(), a.end() #define revall(a) a.rbegin(), a.rend() #define loop(i, s, e) for (int i = s; i < e; ++i) #define inp(v) for (auto& x : v) cin >> x #define outp(v) for (int i = 0, n = v.size(); i < n; ++i) cout << v[i] << " \n"[i == n - 1] #define nl "\n" #define yep cout << "YES\n" #define nope cout << "NO\n" #define INF (int) 1e9 #define INFL (ll) 1e18 // #define MOD 998244353 #define MOD 1000000007 #define MAXN 100002 // ============================================= void solve(int tc) { int n; cin >> n; VI a(n); inp(a); sort(revall(a)); VLL pre(n + 1); loop(i, 1, n + 1) pre[i] = pre[i - 1] + a[i - 1]; ll ans = 0; loop(i, 1, n) { ans += 1LL * a[i] * i; int r = i; for (int j = 1; a[i] * j <= a[0]; ++j) { int l = upper_bound(a.begin(), a.begin() + r, (j + 1) * a[i], greater()) - a.begin(); if (l < r) { ans -= pre[r] - pre[l]; ans += 1LL * (r - l) * j * a[i]; r = l; } } } cout << ans << nl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; // cin >> t; int x = t; while(t--) solve(x - t); #ifdef LOCAL cerr << "Execution time: " << 1000.f * clock() / CLOCKS_PER_SEC << " ms." << nl; #endif return 0; }