This documentation is automatically generated by online-judge-tools/verification-helper
// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2968
#include <bits/stdc++.h>
using namespace std;
#define call_from_test
#include "../../io/single.cpp"
#include "../../tools/chminmax.cpp"
#include "../../math/factorize.cpp"
#include "../../vector/compress.cpp"
#undef call_from_test
signed main(){
cin.tie(0);
ios::sync_with_stdio(0);
int n;
cin>>n;
auto as=read(n);
vector<int> ps;
for(auto a:as)
for(auto[p,_]:factorize(a))
ps.emplace_back(p);
long long ans=0;
for(int p:compress(ps)){
long long res=0;
for(int a:as)
if(a%p==0) res+=a;
chmax(ans,res);
}
cout<<ans<<endl;
return 0;
}
#line 1 "test/aoj/2968.test.cpp"
// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2968
#include <bits/stdc++.h>
using namespace std;
#define call_from_test
#line 1 "io/single.cpp"
#line 3 "io/single.cpp"
using namespace std;
#endif
//BEGIN CUT HERE
template<typename T=int>
vector<T> read(size_t n){
vector<T> ts(n);
for(size_t i=0;i<n;i++) cin>>ts[i];
return ts;
}
//END CUT HERE
#ifndef call_from_test
signed main(){
return 0;
}
#endif
#line 1 "tools/chminmax.cpp"
#line 3 "tools/chminmax.cpp"
using namespace std;
#endif
//BEGIN CUT HERE
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
//END CUT HERE
#ifndef call_from_test
signed main(){
return 0;
}
#endif
#line 1 "math/factorize.cpp"
#line 3 "math/factorize.cpp"
using namespace std;
#endif
//BEGIN CUT HERE
template<typename T>
map<T, int> factorize(T x){
map<T, int> res;
for(int i=2;i*i<=x;i++){
while(x%i==0){
x/=i;
res[i]++;
}
}
if(x!=1) res[x]++;
return res;
}
//END CUT HERE
#ifndef call_from_test
//INSERT ABOVE HERE
signed main(){
return 0;
}
#endif
#line 1 "vector/compress.cpp"
#line 3 "vector/compress.cpp"
using namespace std;
#endif
//BEGIN CUT HERE
template<typename V>
V compress(V vs){
sort(vs.begin(),vs.end());
vs.erase(unique(vs.begin(),vs.end()),vs.end());
return vs;
}
template<typename T>
map<T, int> dict(const vector<T> &vs){
map<T, int> res;
for(int i=0;i<(int)vs.size();i++)
res[vs[i]]=i;
return res;
}
map<char, int> dict(const string &s){
return dict(vector<char>(s.begin(),s.end()));
}
template<typename T>
vector<T> compressed(vector<T> vs){
auto dc=dict(compress(vs));
for(auto &v:vs) v=dc[v];
return vs;
}
//END CUT HERE
#ifndef call_from_test
//INSERT ABOVE HERE
signed main(){
return 0;
}
#endif
#line 11 "test/aoj/2968.test.cpp"
#undef call_from_test
signed main(){
cin.tie(0);
ios::sync_with_stdio(0);
int n;
cin>>n;
auto as=read(n);
vector<int> ps;
for(auto a:as)
for(auto[p,_]:factorize(a))
ps.emplace_back(p);
long long ans=0;
for(int p:compress(ps)){
long long res=0;
for(int a:as)
if(a%p==0) res+=a;
chmax(ans,res);
}
cout<<ans<<endl;
return 0;
}