#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include #include using namespace std; using namespace atcoder; using ll = long long; using pl = std::pair; using mint = atcoder::modint1000000007; //using mint = atcoder::modint998244353; #define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++) #define all(v) (v).begin(), (v).end() #define dump(var) do{ if(debug::enable) { std::cerr << #var << " : "; debug::print(var); } } while(0); constexpr int di[4] = {1, -1, 0, 0}; constexpr int dj[4] = {0, 0, 1, -1}; constexpr long long inf = 1LL<<60; template inline void chmax(T &a, T b) { a = std::max(a, b); }; template inline void chmin(T &a, T b) { a = std::min(a, b); }; template void vprint(const std::vector& v) { for(int i = 0; i < v.size(); i++) { std::cout << v[i] << (i == v.size()-1 ? "\n" : " "); } } template void vprintln(const std::vector& v) { for(int i = 0; i < v.size(); i++) { std::cout << v[i] << "\n"; } } template void vprint(const std::vector>& v) { for(int i = 0; i < v.size(); i++) { std::cout << v[i].val() << (i == v.size()-1 ? "\n" : " "); } } template void vprintln(const std::vector>& v) { for(int i = 0; i < v.size(); i++) { std::cout << v[i].val() << "\n"; } } namespace debug { #if defined(ONLINE_JUDGE) const bool enable = false; #else const bool enable = true; #endif template void push(const T& e) { std::cerr << e; } template void push(const atcoder::static_modint& e) { std::cerr << e.val(); } template void push(const std::pair& e) { std::cerr << "("; push(e.first); std::cerr << ","; push(e.second); std::cerr << ")"; } template void push(const std::tuple& e) { std::cerr << "("; push(get<0>(e)); std::cerr << ","; push(get<1>(e)); std::cerr << ","; push(get<2>(e)); std::cerr << ")"; } template void print(const T& e) { push(e); std::cerr << "\n"; } template void print(const std::vector& v) { for(int i = 0; i < v.size(); i++) { push(v[i]); std::cerr << " "; } std::cerr << "\n"; } template void print(const std::vector>& v) { std::cerr << "\n"; for(int i = 0; i < v.size(); i++) { std::cerr << i << ": "; print(v[i]); } } }; void solve() { ll n; cin >> n; vector a(n); rep(i, 0, n) cin >> a[i]; sort(all(a)); ll ans = 0; rep(i, 0, n) { const int mod = a[i]; ans += (n - (i+1)) * (ll)a[i]; int tmp = a[i]; rep(j, i+1, n) { int tmp2 = a[j] - tmp; if(tmp2 >= mod) { tmp = a[j] / mod * mod; tmp2 = a[j] - tmp; } ans -= tmp2; } } cout << ans << endl; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); solve(); return 0; }