#include #include #include using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 4000000000000000001 int main(){ int n; cin>>n; vector a(n); rep(i,n){ cin>>a[i]; } sort(a.begin(),a.end()); long long ans = 0; rep(i,n-1)ans += a[i]; ans += a[n-1]%a[0]; vector dp(3,-Inf64); dp[0] = 0; for(int i=1;i ndp = dp;//(3,-Inf64); { ndp[1] = max(ndp[1],dp[0] - a.back()%a[0] + a.back()%a[i]); } { ndp[2] = max(ndp[2],dp[1] - a[i] + a[i]%a[0]); } { ndp[2] = max(ndp[2],dp[0] - a[i] + a[i]%a[0] - a.back()%a[0] + a.back()%a[i]); } swap(dp,ndp); } ans += max({dp[0],dp[2]}); cout<