#include using namespace std; using ll = long long; #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") 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; }