#include #define loop(i,n) for( int i=0; i::iterator i=a.begin(); i!=a.end(); i++ ) #define dloop(i,a) for( deque::iterator i=a.begin(); i!=a.end(); i++ ) #define PI 3.14159265 #define bc __builtin_popcountl #define gc getchar_unlocked #define pc putchar_unlocked #define pb push_back #define pf push_front #define rf pop_front #define rb pop_back #define mp make_pair #define fs first #define sc second #define fi ios_base::sync_with_stdio(false); cin.tie(NULL) using namespace std; typedef long long ll; typedef unsigned long long ull; const ll M = 1e9 + 7; const ll INF = 1e9; inline ll pwr(ll base,ll n,ll m){ll ans=1;while(n>0){if(n%2==1)ans=(ans*base)%m;base=(base*base)%m;n/=2;}return ans;} int n, ind; bool prime[1000002]; vectorprimes, pfs[101]; unordered_mapcache; void sieve() { memset(prime,true,sizeof(prime)); prime[1] = false; loop1(i,2,1000001) { if( prime[i] ) { primes.pb(i); int j = i*2; while( j <= 1000000 ) { prime[j] = false; j += i; } } } } ll solve( ll num ) { if( num == 1 ) return 1; if( cache[num] != 0 ) return cache[num]; ll mx = num+1; vloop( j, pfs[ind] ) { if( num % (*j) == 0 ) { ll f = num/(*j); mx = max(mx, num + solve(f)); } else if( (*j) > num/2 )break; } return cache[num] = mx; } ll longestSequence( vectora ) { ll sum = 0; loop(i,n) { vloop(j,primes) { if( a[i] % (*j) == 0 ) { pfs[i].pb(*j); } else if( (*j) > a[i]/2 ) break; } ind = i; sum += solve(a[i]); } return sum; } int main() { fi; sieve(); cin>>n; vector a(n); loop(i,n) cin>>a[i]; cout<