#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]; } ll ans = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { ans += abs(a[i] % a[j] - a[j] % a[i]); } } cout << ans << endl; }