#include using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector a(n, 0); for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a.begin(), a.end()); ll ans = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { ans += a[i] - a[j] % a[i]; } } cout << ans << endl; }