#include #include #include using namespace std; int main() { int n; cin >> n; int a[n]; long long s[n+1]; s[0] = 0; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a+n); for (int i = 0; i < n; i++) { s[i+1] = s[i] + a[i]; } long long ans = 0; unordered_map cnt; for (int i = 0; i < n; i++) cnt[a[i]]++; for (auto [x, c] : cnt) { for (int m = 0; m <= 2e5; m += x) { int l = lower_bound(a, a+n, m) - a, r = lower_bound(a, a+n, m+x) - a; ans += c * (s[r] - s[l] - (long long)m * (r - l)); } } cout << ans << endl; }