Problem:
Problem Statement
You are given a positive integer sequence $A$ of length $N$. You can remove any numbers from the sequence to make the sequence “friendly". 
A sequence is called friendly if there exists an integer $k$ (>1) such that every number in the sequence is a multiple of $k$.
Since the empty sequence is friendly, it is guaranteed that you can make the initial sequence friendly.
You noticed that there may be multiple ways to make the sequence friendly. So you decide to maximize the sum of all the numbers in the friendly sequence. Please calculate the maximum sum of the all numbers in the friendly sequence which can be obtained from the initial sequence.
Input
The input consists of a single test case formatted as follows.
$N$
$A_1$
$\vdots$
$A_N$
The first line consists of a single integer $N$ ($1 \le N \le 1000$). The $i+1$-st line consists of an integer $A_i$ ($1 \le A_i \le 10^9$ for $1 \le i \le N$).
Output
Print the maximum sum of all the numbers in the friendly sequence which can be obtained from the initial sequence.
Examples
Input
Output
6
1
2
3
4
5
6
12
3
173
1733
111733
111733
4
1
1
1
1
0
10
999999999
999999999
999999999
999999999
999999999
999999999
999999999
999999999
999999999
999999999
9999999990
1
999999999
999999999
10
28851
8842
9535
2311
25337
26467
12720
10561
8892
6435
56898

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rrep(i,start,end) for (ll i = start;i >= (ll)(end);i--)
#define repn(i,end) for(ll i = 0; i <= (ll)(end); i++)
#define reps(i,start,end) for(ll i = start; i < (ll)(end); i++)
#define repsn(i,start,end) for(ll i = start; i <= (ll)(end); i++)
#define each(p,a) for(auto &p:a)
typedef vector<ll> vll;
typedef vector<pair<ll ,ll>> vpll;
typedef vector<vector<pair<ll ,ll>>> vvpll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef set<ll> sll;
typedef map<ll , ll> mpll;
typedef pair<ll ,ll> pll;
typedef tuple<ll , ll , ll> tpl3;
typedef tuple<ll , ll , ll , ll> tpl4;
typedef tuple<ll , ll , ll , ll , ll> tpl5;
typedef tuple<ll , ll , ll , ll , ll , ll> tpl6;
#define LL(...) ll __VA_ARGS__; input(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__; input(__VA_ARGS__)
#define Str(...) string __VA_ARGS__; input(__VA_ARGS__)
#define Ch(...) char __VA_ARGS__; input(__VA_ARGS__)
#define all(a)  (a).begin(),(a).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define sz(x) (ll)x.size()
// << std::fixed << std::setprecision(10)
const ll INF = 1LL << 60;
const ld EPS = 1e-9;
 
ll lceil(ll a,ll b){if(a%b==0){return a/b;}if(a>=0){return (a/b)+1;}else{return -((-a)/b);}}
ll lfloor(ll a,ll b){if(a%b==0){return a/b;}if(a>=0){return (a/b);}else{return -((-a)/b)-1;}}
inline ll positive_mod(ll a,ll m){return (a % m + m)%m;}
inline ll popcnt(ull a){ return __builtin_popcountll(a);}
//0indexed
inline ll topbit(ll a){assert(a != 0);return 63 - __builtin_clzll(a);}
inline ll smlbit(ll a){assert(a != 0);return __builtin_ctzll(a);}
template<class T> bool chmin(T& a, T b){if(a > b){a = b;return true;}return false;}
template<class T> bool chmax(T& a, T b){if(a < b){a = b;return true;}return false;}
template<typename T> std::istream &operator>>(std::istream&is,std::vector<T>&v){for(T &in:v){is>>in;}return is;}
template<typename T> std::ostream &operator<<(std::ostream&os,const std::vector<T>&v){for(auto it=std::begin(v);it!=std::end(v);){os<<*it<<((++it)!=std::end(v)?" ":"");}return os;}
template<typename T1, typename T2>std::ostream &operator<< (std::ostream &os, std::pair<T1,T2> p){os << "{" << p.first << "," << p.second << "}";return os;}
template<class... T>void input(T&... a){(cin >> ... >> a);}
void print(){cout << endl;}
template<class T, class... Ts>void print(const T& a, const Ts&... b){cout << a;((cout << ' ' << b), ...);cout << endl;}
template<class T> void pspace(const T& a){ cout << a << ' ';}
void perr(){cerr << endl;}
template<class T, class... Ts>void perr(const T& a, const Ts&... b){cerr << a;((cerr << ' ' << b), ...);cerr << endl;}
void yes(bool i = true){ return print(i?"yes":"no"); }
void Yes(bool i = true){ return print(i?"Yes":"No"); }
void YES(bool i = true){ return print(i?"YES":"NO"); }
template <class T> vector<T> &operator++(vector<T> &v) {for(auto &e : v) e++;return v;}
template <class T> vector<T> operator++(vector<T> &v, signed) {auto res = v;for(auto &e : v) e++;return res;}
template <class T> vector<T> &operator--(vector<T> &v) {for(auto &e : v) e--;return v;}
template <class T> vector<T> operator--(vector<T> &v, signed) {auto res = v;for(auto &e : v) e--;return res;}
//grid探索用
vector<ll> _ta = {0,0,1,-1,1,1,-1,-1};
vector<ll> _yo = {1,-1,0,0,1,-1,1,-1};
bool isin(ll now_i,ll now_j,ll h,ll w){return (0<=now_i && now_i < h && 0 <= now_j && now_j < w);}
  
ll lpow(ll x,ll n){ll ans = 1;while(n >0){if(n & 1)ans *= x;x *= x;n >>= 1;}return ans;}
ll Modlpow(ll x,ll n,ll m){ll ans = 1;ll a = x%m;while(n >0){if(n & 1){ans *= a;ans%= m;}a *= a;a %= m;n >>= 1;}return ans;} 
const ll MOD9 = 998244353LL;
const ll MOD10 = 1000000007LL;

//素因数分解
map<ll,ll> enumpr(ll n) {
 map<ll,ll> V;
 for(ll i=2;i*i<=n;i++) {
    while(n%i==0){
      V[i]++;
      n/=i;
    } 
  }
 if(n>1) V[n]++;
 return V;
}
 
int main(){
  ios::sync_with_stdio(false);cin.tie(nullptr);
  LL(n);
  vll a(n);cin >> a;
  set<ll> se;
  rep(i,n){
    map<ll,ll> mp = enumpr(a[i]);
    each(p,mp){
      se.insert(p.first);
    }
  }
  if(*max_element(all(a)) == 1){
    cout << 0 << endl;
    return 0;
  }
  ll ma = 0;
  each(p,se){
    ll now = 0;
    rep(i,n){
      if(a[i] %p==0)now+=a[i];
    }
    chmax(ma,now);
  }
  cout << ma << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3712
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using a2 = array<ll, 2>;
using a3 = array<ll, 3>;

bool chmin(auto& a, const auto& b) { return a > b ? a = b, 1 : 0; }
bool chmax(auto& a, const auto& b) { return a < b ? a = b, 1 : 0; }

const ll INF = 1e18;
ll mod = 998244353;

ifstream in;
ofstream out;

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    if (argc > 2) {
        in.open(argv[1]);
        cin.rdbuf(in.rdbuf());
        out.open(argv[2]);
        cout.rdbuf(out.rdbuf());
    }

    map<ll, ll> mp;
    ll n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        ll a;
        cin >> a;
        if (a == 1)
            continue;
        mp[a] += a;
        for (ll j = 2; j * j <= a; j++) {
            if (a % j == 0) {
                mp[a / j] += a;
                if (a / j != j)
                    mp[j] += a;
            }
        }
    }
    ll ans = 0;
    for (auto& x : mp) {
        chmax(ans, x.second);
    }
    cout << ans << endl;

    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 4864
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define vl vector<ll>
#define vvl vector<vl>
#define rep(i, n) for (ll i = 0; i < n; ++i)

vector<ll> enum_divisors(ll n) {
    vector<ll> res;
    res.reserve(100);
    for (ll i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            res.push_back(i);
            if (i * i != n) res.push_back(n / i);
        }
    }
    return res;
}

int main() {
    ll n; cin >> n;
    vl a(n);
    rep(i, n) {
        cin >> a[i];
    }

    map<ll, ll> sum;
    rep(i, n) {
        vl divs = enum_divisors(a[i]);
        for (ll d : divs) {
            sum[d] += a[i];
        }
    }

    ll ans = 0;
    for (auto [d, val] : sum) {
        if (d <= 1) continue;
        ans = max(ans, val);
    }

    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 4864
final_rank: 11

code_snippet: #include<bits/stdc++.h>
// #include<atcoder/all>
// #include<boost/multiprecision/cpp_int.hpp>

using namespace std;
// using namespace atcoder;
// using bint = boost::multiprecision::cpp_int;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ve = vector<vector<int>>;
using vb = vector<bool>;
using vvb = vector<vb>;
#define rep(i,s,n) for(ll i = (ll)s;i < (ll)n;i++)
#define rrep(i,l,r) for(ll i = r-1;i >= l;i--)
#define ALL(x) (x).begin(),(x).end()
#define sz(c) ((ll)(c).size())
#define LB(A,x) (int)(lower_bound(A.begin(),A.end(),x)-A.begin())
#define UB(A,x) (int)(upper_bound(A.begin(),A.end(),x)-A.begin())
// #define MOD 1000000007
#define MOD 998244353
template<typename T>using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<typename T>ostream&operator<<(ostream&os,vector<T>&v){for(int i = 0;i < v.size();i++)os<<v[i]<<(i+1!=v.size()?" ":"");return os;}
template<typename T>istream&operator>>(istream&is,vector<T>&v){for(T&in:v)is>>in;return is;}
template<typename T1,typename T2>ostream&operator<<(ostream&os,pair<T1,T2>&p){os<<p.first<<" "<<p.second;return os;}
template<typename T1,typename T2>istream&operator>>(istream&is,pair<T1,T2>&p){is>>p.first>>p.second;return is;}
template<typename T> inline bool chmax(T &a,T b){if(a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a,T b){if(a > b){a = b;return true;}return false;}
ld dist(ld x1,ld y1,ld x2, ld y2){return sqrtl((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}


int main(){
  
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n;cin >> n;
  map<ll,ll> mp;
  rep(i,0,n){
    ll a;cin >> a;
    for(ll i = 1;i*i <= a;i++){
      if(a%i != 0)continue;
      if(i > 1)mp[i] += a;
      if(i*i != a && a/i > 1)mp[a/i] += a;
    }
  }
  ll res = 0;
  for(auto au : mp)chmax(res,au.second);
  cout << res << endl;
  

  return 0;
}
accuracy: 1
time_ms: 190
memory_kb: 4580
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define append push_back
#define add insert
#define ll long long
#define pii pair<int,int>
#define ff first
#define ss second
#define nl endl
#define pll pair<long, long>
#define all(x) x.begin(), x.end()
#define N 1000

ll a[N];

void solve(){
	int n;
	cin >> n;
	ll ans, o;
	set<int> d;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		for(int j = 1; j * j <= a[i]; j++){
			if(a[i] % j) continue;
			d.add(a[i] / j);
			d.add(j);
		}
	}
	// cerr<<n<<endl;
	ans = 0;
	d.erase(1);
	for(auto x : d){
		for(int i = o = 0; i < n; i++){
			if(a[i] % x == 0) o += a[i];
		}
		ans = max(ans, o);
	}
	cout << ans << nl;
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int t;
	t = 1;
	while(t--)
		solve();
	return 0;
}
accuracy: 1
time_ms: 340
memory_kb: 4436
final_rank: 18

code_snippet: #include<bits/stdc++.h>
using namespace std;

using ll = long long;

int main(){
	int n;
	cin >> n;
	vector<ll> a(n);
	for(int i = 0; i < n; ++i) cin >> a[i];
	vector<map<int, ll>> dp(n+1);
	dp[0][0] = 0;
	for(int i = 0; i < n; ++i){
		for(auto [g, j]: dp[i]){
			dp[i+1][gcd(g, a[i])] = max(dp[i+1][gcd(g, a[i])], j+a[i]);
			dp[i+1][g] = max(dp[i+1][g], j);
		}
	}
	ll ans = 0;
	for(auto [g, i]: dp[n]){
		if(g == 0 || g == 1) continue;
		ans = max(ans, i);
	}
	cout << ans << endl;
	return 0;
}
accuracy: 1
time_ms: 190
memory_kb: 56960
final_rank: 19

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
int N, A[1000];
int main() {
    std::cin >> N;
    for (int i{} ; i < N ; i++) std::cin >> A[i];
    std::vector<int> p;
    for (int i{} ; i < N ; i++) {
        int B{A[i]};
        for (int j{2} ; j * j <= B ; j++) if (B % j == 0) {
            p.push_back(j);
            while (B % j == 0) B /= j;
        }
        if (B > 1) p.push_back(B);
    }
    std::sort(p.begin(), p.end());
    long long ans{};
    for (auto x : p) {
        long long v{};
        for (int i{} ; i < N ; i++) if (A[i] % x == 0) v += A[i];
        ans = std::max(ans, v);
    }
    std::cout << ans << '\n';
}
accuracy: 1
time_ms: 10
memory_kb: 3460
final_rank: 1

code_snippet: #include <iostream>
#include <vector>
#include <set>
#include <cmath>

// x <= 10^9
std::vector<int> factorization(int x) {
	std::vector<int> ret;
	for(int i=2;i*i<=x;++i) {
		while(x%i == 0) {
			ret.push_back(i);
			x /= i;
		}
	}
	if(x != 1) ret.push_back(x);
	return ret;
}

std::vector<int> make_divisors(int x) {
	std::vector<int> res;
	int i = 1;
	while(i*i <= x) {
		if(x%i == 0) {
			res.push_back(i);
			if(i != x / i) {
				res.push_back(x/i);
			}
		}
		i++;
	}
	return res;
}

int main() {
	int n;
	std::cin >> n;
	
	std::vector<int> a(n);
	for(int i=0;i<n;++i) {
		std::cin >> a[i];
	}

	std::set<int> list;
	for(int i=0;i<n;++i) {
		for(auto x : make_divisors(a[i])) {
			list.insert(x);
		}
	}
	
	list.erase(1);
	long long ans = 0;
	for(auto k : list) {
		long long t = 0;
		for(int i=0;i<n;++i) {
			if(a[i]%k == 0) t += a[i];
		}
		ans = std::max(ans, t);
	}
	std::cout << ans << std::endl;
}
accuracy: 1
time_ms: 100
memory_kb: 4416
final_rank: 14

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

#include <unistd.h>

namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf


uint32_t pil = 0, pir = 0, por = 0;

struct Pre {
    char num[10000][4];
    constexpr Pre() : num() {
        for (int i = 0; i < 10000; i++) {
            int n = i;
            for (int j = 3; j >= 0; j--) {
                num[i][j] = n % 10 | '0';
                n /= 10;
            }
        }
    }
} constexpr pre;

inline void load() {
    memmove(ibuf, ibuf + pil, pir - pil);
    pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
    pil = 0;
    if (pir < SZ)
        ibuf[pir++] = '\n';
}

inline void flush() {
    fwrite(obuf, 1, por, stdout);
    por = 0;
}

void rd(char &c) {
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
}

void rd(string &x) {
    x.clear();
    char c;
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
    do {
        x += c;
        if (pil == pir)
            load();
        c = ibuf[pil++];
    } while (!isspace(c));
}

template <typename T> void rd_real(T &x) {
    string s;
    rd(s);
    x = stod(s);
}

template <typename T> void rd_integer(T &x) {
    if (pil + 100 > pir)
        load();
    char c;
    do
        c = ibuf[pil++];
    while (c < '-');
    bool minus = 0;
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (c == '-') {
            minus = 1, c = ibuf[pil++];
        }
    }
    x = 0;
    while ('0' <= c) {
        x = x * 10 + (c & 15), c = ibuf[pil++];
    }
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (minus)
            x = -x;
    }
}

void rd(int &x) {
    rd_integer(x);
}
void rd(ll &x) {
    rd_integer(x);
}
void rd(i128 &x) {
    rd_integer(x);
}
void rd(uint &x) {
    rd_integer(x);
}
void rd(ull &x) {
    rd_integer(x);
}
void rd(u128 &x) {
    rd_integer(x);
}
void rd(double &x) {
    rd_real(x);
}
void rd(long double &x) {
    rd_real(x);
}

template <class T, class U> void rd(pair<T, U> &p) {
    return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T> void rd_tuple(T &t) {
    if constexpr (N < std::tuple_size<T>::value) {
        auto &x = std::get<N>(t);
        rd(x);
        rd_tuple<N + 1>(t);
    }
}
template <class... T> void rd(tuple<T...> &tpl) {
    rd_tuple(tpl);
}

template <size_t N = 0, typename T> void rd(array<T, N> &x) {
    for (auto &d : x)
        rd(d);
}
template <class T> void rd(vector<T> &x) {
    for (auto &d : x)
        rd(d);
}

void read() {}
template <class H, class... T> void read(H &h, T &...t) {
    rd(h), read(t...);
}

void wt(const char c) {
    if (por == SZ)
        flush();
    obuf[por++] = c;
}
void wt(const string s) {
    for (char c : s)
        wt(c);
}
void wt(const char *s) {
    size_t len = strlen(s);
    for (size_t i = 0; i < len; i++)
        wt(s[i]);
}

template <typename T> void wt_integer(T x) {
    if (por > SZ - 100)
        flush();
    if (x < 0) {
        obuf[por++] = '-', x = -x;
    }
    int outi;
    for (outi = 96; x >= 10000; outi -= 4) {
        memcpy(out + outi, pre.num[x % 10000], 4);
        x /= 10000;
    }
    if (x >= 1000) {
        memcpy(obuf + por, pre.num[x], 4);
        por += 4;
    } else if (x >= 100) {
        memcpy(obuf + por, pre.num[x] + 1, 3);
        por += 3;
    } else if (x >= 10) {
        int q = (x * 103) >> 10;
        obuf[por] = q | '0';
        obuf[por + 1] = (x - q * 10) | '0';
        por += 2;
    } else
        obuf[por++] = x | '0';
    memcpy(obuf + por, out + outi + 4, 96 - outi);
    por += 96 - outi;
}

template <typename T> void wt_real(T x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << double(x);
    string s = oss.str();
    wt(s);
}

void wt(int x) {
    wt_integer(x);
}
void wt(ll x) {
    wt_integer(x);
}
void wt(i128 x) {
    wt_integer(x);
}
void wt(uint x) {
    wt_integer(x);
}
void wt(ull x) {
    wt_integer(x);
}
void wt(u128 x) {
    wt_integer(x);
}
void wt(double x) {
    wt_real(x);
}
void wt(long double x) {
    wt_real(x);
}

template <class T, class U> void wt(const pair<T, U> val) {
    wt(val.first);
    wt(' ');
    wt(val.second);
}
template <size_t N = 0, typename T> void wt_tuple(const T t) {
    if constexpr (N < std::tuple_size<T>::value) {
        if constexpr (N > 0) {
            wt(' ');
        }
        const auto x = std::get<N>(t);
        wt(x);
        wt_tuple<N + 1>(t);
    }
}
template <class... T> void wt(tuple<T...> tpl) {
    wt_tuple(tpl);
}
template <class T, size_t S> void wt(const array<T, S> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}
template <class T> void wt(const vector<T> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}

void print() {
    wt('\n');
}
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
    wt(head);
    if (sizeof...(Tail))
        wt(' ');
    print(forward<Tail>(tail)...);
}
void __attribute__((destructor)) _d() {
    flush();
}
} // namespace fastio


using fastio::flush;
using fastio::print;
using fastio::read;

inline void first(bool i = true) {
    print(i ? "first" : "second");
}
inline void Alice(bool i = true) {
    print(i ? "Alice" : "Bob");
}
inline void Takahashi(bool i = true) {
    print(i ? "Takahashi" : "Aoki");
}
inline void yes(bool i = true) {
    print(i ? "yes" : "no");
}
inline void Yes(bool i = true) {
    print(i ? "Yes" : "No");
}
inline void No() {
    print("No");
}
inline void YES(bool i = true) {
    print(i ? "YES" : "NO");
}
inline void NO() {
    print("NO");
}
inline void Yay(bool i = true) {
    print(i ? "Yay!" : ":(");
}
inline void Possible(bool i = true) {
    print(i ? "Possible" : "Impossible");
}
inline void POSSIBLE(bool i = true) {
    print(i ? "POSSIBLE" : "IMPOSSIBLE");
}

/**
 * @brief Fast IO
 */

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i,0,N) cin >> A[i];
    vector<int> X;
    rep(i,0,N) {
        int B = A[i];
        rep(j,2,100000) {
            if (j*j > B) break;
            if (B % j == 0) {
                X.push_back(j);
                while(B % j == 0) B /= j;
            }
        }
        if (B > 1) X.push_back(B);
    }
    UNIQUE(X);
    ll ANS = 0;
    for (int B : X) {
        ll COUNT = 0;
        rep(i,0,N) {
            if (A[i] % B == 0) COUNT += A[i];
        }
        chmax(ANS, COUNT);
    }
    cout << ANS << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3548
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;
signed main() {
    cin.tie(0); ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    long long ans = 0;
    map<int, long long> sum_multiple;
    for (int i = 0; i < n; i++) {
    	int x;
    	cin >> x;
    	for (int j = 1; j * j <= x; j++) {
    		if (x % j == 0) {
    			sum_multiple[j] += x;
    			if (j * j != x) sum_multiple[x / j] += x;
    			if (j != 1) ans = max(ans, sum_multiple[j]);
    			if (x / j != 1) ans = max(ans, sum_multiple[x / j]);
    		}
    	}
    }
    cout << ans << "\n";
}
accuracy: 1
time_ms: 70
memory_kb: 4520
final_rank: 10

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define ti3 tuple<int,int,int>
#define int128 __int128_t
#define pii128 pair<int128,int128>
const int inf = 1 << 30;
const ll linf = (ll)4e18 + 10;;
const db EPS = 1e-10;
const db pi = acos(-1);
template<class T> bool chmin(T& x, T y){
    if(x > y) {
        x = y;
        return true;
    } else return false;
}
template<class T> bool chmax(T& x, T y){
    if(x < y) {
        x = y;
        return true;
    } else return false;
}

// overload macro
#define CAT( A, B ) A ## B
#define SELECT( NAME, NUM ) CAT( NAME, NUM )

#define GET_COUNT( _1, _2, _3, _4, _5, _6 /* ad nauseam */, COUNT, ... ) COUNT
#define VA_SIZE( ... ) GET_COUNT( __VA_ARGS__, 6, 5, 4, 3, 2, 1 )

#define VA_SELECT( NAME, ... ) SELECT( NAME, VA_SIZE(__VA_ARGS__) )(__VA_ARGS__)

// rep(overload)
#define rep( ... ) VA_SELECT(rep, __VA_ARGS__)
#define rep2(i, n) for (int i = 0; i < int(n); i++)
#define rep3(i, a, b) for (int i = a; i < int(b); i++)
#define rep4(i, a, b, c) for (int i = a; i < int(b); i += c)

// repll(overload)
#define repll( ... ) VA_SELECT(repll, __VA_ARGS__)
#define repll2(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repll3(i, a, b) for (ll i = a; i < (ll)(b); i++)
#define repll4(i, a, b, c) for (ll i = a; i < (ll)(b); i += c)

// rrep(overload)
#define rrep( ... ) VA_SELECT(rrep, __VA_ARGS__)
#define rrep2(i, n) for (int i = n - 1; i >= 0; i--)
#define rrep3(i, a, b) for (int i = (b) - 1; i >= a; i--)
#define rrep4(i, a, b, c) for (int i = (b) - 1; i >= a; i -= c)

// rrepll(overload)
#define rrepll( ... ) VA_SELECT(rrepll, __VA_ARGS__)
#define rrepll2(i, n) for (ll i = (ll)(n) - 1; i >= 0ll; i--)
#define rrepll3(i, a, b) for (ll i = (b) - 1; i >= (ll)(a); i--)
#define rrepll4(i, a, b, c) for (ll i = (b) - 1; i >= (ll)(a); i -= c)

// for_earh
#define fore(e, v) for (auto&& e : v)

// vector
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()


const int MAX_N = 1e6;

bool prm[MAX_N + 10];
vector<int> ps;

void prime(int N){
    for(int i = 2; i <= N; i++) prm[i] = true;
    for(int i = 2; i <= N; i++){
        if(prm[i]){
            ps.push_back(i);
            for(int j = i * 2; j <= N; j += i){
                prm[j] = false;
            }
        }
    }
}

template<class T>
vector<pair<T, int>> prime_fac(T N){
    vector<pair<T, int>> res;
    T cp = N;
    for(ll i = 0; i < (int)ps.size() && ps[i] * ps[i] <= cp; ++i){
        int cnt = 0;
        while(N % ps[i] == 0) N /= ps[i], cnt++;
        if(cnt != 0) res.push_back({ps[i], cnt});
        
    }
    if(N != 1) res.push_back({N, 1});
    return res;
}

int N, A[1010];
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cin >> N;
    prime(MAX_N);
    map<int, ll> mp;
    rep (i, N) {
        cin >> A[i];
        auto v = prime_fac(A[i]);
        for (auto [num, cnt] : v) {
            mp[num] += A[i];
        }
    }

    ll ans = 0;
    for (auto [key, val] : mp) chmax(ans, val);
    cout << ans << '\n';
}
accuracy: 1
time_ms: 10
memory_kb: 4740
final_rank: 4

code_snippet: #line 2 "cp-library/src/cp-template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull  = unsigned long long;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128_t;
template < class T > bool chmin(T& a, T b) { if(a > b) { a = b; return true; } return false; }
template < class T > bool chmax(T& a, T b) { if(a < b) { a = b; return true; } return false; }
template < class T, class U > T ceil (T x, U y) { return (x > 0 ? (x + y - 1) / y :           x / y); }
template < class T, class U > T floor(T x, U y) { return (x > 0 ?           x / y : (x - y + 1) / y); }
int popcnt(i32 x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(i64 x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }

#line 2 "cp-library/src/utility/rep_itr.hpp"
template < class T > struct itr_rep {
    T i, d;
    constexpr itr_rep(const T i) noexcept : i(i), d(1) {}
    constexpr itr_rep(const T i, const T d) noexcept : i(i), d(d) {}
    void operator++() noexcept { i += d; }
    constexpr int operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr_rep x) const noexcept { return d > 0 ? i < x.i : i > x.i; }
};

template < class T > struct rep {
    const itr_rep< T > s, t;
    constexpr rep(const T t) noexcept : s(0), t(t) {}
    constexpr rep(const T s, const T t) noexcept : s(s), t(t) {}
    constexpr rep(const T s, const T t, const T d) noexcept : s(s, d), t(t, d) {}
    constexpr auto begin() const noexcept { return s; }
    constexpr auto end  () const noexcept { return t; }
};

template < class T > struct revrep {
    const itr_rep < T > s, t;
    constexpr revrep(const T t) noexcept : s(t - 1, -1), t(-1, -1) {}
    constexpr revrep(const T s, const T t) noexcept : s(t - 1, -1), t(s - 1, -1) {}
    constexpr revrep(const T s, const T t, const T d) noexcept : s(t - 1, -d), t(s - 1, -d) {}
    constexpr auto begin() const noexcept { return s; }
    constexpr auto end  () const noexcept { return t; }
};
#line 3 "cp-library/src/utility/io.hpp"

/* 128bit integer */
istream& operator>>(istream& is, i128& x) {
    std::string s; is >> s;
    int pm = (s[0] == '-');
    x = 0;
    for(int i : rep(pm, int(s.size()))) x = x * 10 + (s[i] - '0');
    if(pm) x *= -1;
    return is;
}
ostream& operator<<(ostream& os, const i128& x) {
    if(x == 0) return os << '0';
    i128 y = x;
    if(y < 0) { os << '-'; y *= -1; }
    std::vector<int> ny;
    while(y > 0) { ny.push_back(y % 10); y /= 10; }
    for(int i : revrep(ny.size())) os << ny[i];
    return os;
}

template < class S, class T > istream& operator>>(istream& is,       std::pair< S, T >& x) { is >> x.first        >> x.second; return is; }
template < class S, class T > ostream& operator<<(ostream& os, const std::pair< S, T >& x) { os << x.first << " " << x.second; return os; }

namespace scanner {
    struct sca {
        template < class T > operator T() {
            T s; std::cin >> s; return s;
        }
    };
    struct vec {
        int n;
        vec(int n) : n(n) {}
        template < class T > operator std::vector< T >() {
            std::vector< T > v(n);
            for(T& x : v) std::cin >> x;
            return v;
        }
    };
    struct mat {
        int h, w;
        mat(int h, int w) : h(h), w(w) {}
        template < class T > operator std::vector< std::vector< T > >() {
            std::vector m(h, std::vector< T >(w));
            for(std::vector< T >& v : m) for(T& x : v) std::cin >> x;
            return m;
        }
    };
    struct speedup {
        speedup() {
            std::cin.tie(0);
            std::ios::sync_with_stdio(0);
        }
    } speedup_instance;
}
scanner::sca in() { return scanner::sca(); }
scanner::vec in(int n) { return scanner::vec(n); }
scanner::mat in(int h, int w) { return scanner::mat(h, w); }

namespace printer {
    void precision(int d) { std::cout << std::fixed << std::setprecision(d); }
    void flush() { std::cout.flush(); }
}

template < class T >
ostream& operator<<(ostream& os, const std::vector< T > a) {
    int n = a.size();
    for(int i : rep(n)) { os << a[i]; if(i != n - 1) os << ' '; }
    return os;
}

int print() { std::cout << '\n'; return 0; }
template < class head, class... tail > int print(head&& h, tail&&... t) {
    std::cout << h; if(sizeof...(tail)) std::cout << ' ';
    return print(std::forward<tail>(t)...);
}
template < class T > int print_n(const std::vector< T > a) {
    int n = a.size();
    for(int i : rep(n)) std::cout << a[i] << "\n";
    return 0;
}


#line 2 "cp-library/src/utility/key_val.hpp"

template < class K, class V >
struct key_val {
    K key; V val;
    key_val() {}
    key_val(K key, V val) : key(key), val(val) {}
    template < std::size_t Index >
    std::tuple_element_t< Index, key_val >& get() {
        if constexpr (Index == 0) return key;
        if constexpr (Index == 1) return val;
    }
};

namespace std {

template < class K, class V > struct tuple_size < key_val< K, V > > : integral_constant< size_t, 2 > {};
template < class K, class V > struct tuple_element < 0, key_val< K, V > > { using type = K; };
template < class K, class V > struct tuple_element < 1, key_val< K, V > > { using type = V; };

}
#line 2 "cp-library/src/utility/vec_op.hpp"
template < class T > key_val< int, T > max_of(const vector< T >& a) {
    int i = std::max_element(a.begin(), a.end()) - a.begin();
    return {i, a[i]};
}
template < class T > key_val< int, T > min_of(const vector< T >& a) {
    int i = std::min_element(a.begin(), a.end()) - a.begin();
    return {i, a[i]};
}
template < class S, class T > S sum_of(const vector< T >& a) {
    S sum = 0;
    for(const T x : a) sum += x;
    return sum;
}
template < class S, class T > vector< S > freq_of(const vector< T >& a, T L, T R) {
    vector< S > res(R - L, S(0));
    for(const T x : a) res[x - L] += 1;
    return res;
}
template < class S, class T > struct prefix_sum {
    vector< S > s;
    prefix_sum(const vector< T >& a) : s(a) {
        s.insert(s.begin(), S(0));
        for(int i : rep(a.size())) s[i + 1] += s[i];
    }
    // [L, R)
    S sum(int L, int R) { return s[R] - s[L]; }
};
#line 3 "cp-library/src/utility/heap.hpp"

template < class T > using heap_min = std::priority_queue< T, std::vector< T >, std::greater< T > >;
template < class T > using heap_max = std::priority_queue< T, std::vector< T >, std::less< T > >;

#line 27 "cp-library/src/cp-template.hpp"

#line 1 "cp-library/src/algorithm/bin_search.hpp"
template < class T, class F >
T bin_search(T ok, T ng, F f) {
    while(abs(ng - ok) > 1) {
        T mid = (ok + ng) / 2;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}

template < class T, class F >
T bin_search_real(T ok, T ng, F f, int step = 80) {
    while(step--) {
        T mid = (ok + ng) / 2;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}
#line 2 "cp-library/src/algorithm/argsort.hpp"

template < class T > std::vector< int > argsort(const std::vector< T > &a) {
    std::vector< int > ids((int)a.size());
    std::iota(ids.begin(), ids.end(), 0);
    std::sort(ids.begin(), ids.end(), [&](int i, int j) {
        return a[i] < a[j] || (a[i] == a[j] && i < j);
    });
    return ids;
}
#line 1 "macro.hpp"
namespace macro {

using size_type = int;
template < class container > void  sort(container& a) { std::sort(std:: begin(a), std:: end(a)); }
template < class container > void rsort(container& a) { std::sort(std::rbegin(a), std::rend(a)); }
template < class container > void reverse(container& a) { std::reverse(std::begin(a), std::end(a)); }
template < class container > void unique(container& a) {
    std::sort(std::begin(a), std::end(a));
    a.erase(std::unique(std::begin(a), std::end(a)), std::end(a));
}
template < class container > container  sorted(const container& a) { container b = a;  sort(b); return std::move(b); }
template < class container > container rsorted(const container& a) { container b = a; rsort(b); return std::move(b); }
template < class container, class compare > void sort(container& a, const compare& cmp) { std::sort(std::begin(a), std::end(a), cmp); }
template < class container, class compare > container sorted(const container& a, const compare& cmp) { container b = a; sort(b, cmp); return std::move(b); }
template < class container, class value > size_type lower_bound(const container& a, const value& x) { return std::lower_bound(std::begin(a), std::end(a), x) - std::begin(a); }
template < class container, class value > size_type upper_bound(const container& a, const value& x) { return std::upper_bound(std::begin(a), std::end(a), x) - std::begin(a); }

const std::vector<std::pair<size_type, size_type>> dir4 = { {+1,  0}, {-1,  0}, { 0, +1}, { 0, -1} };
const std::vector<std::pair<size_type, size_type>> dir8 = { {-1, -1}, {-1,  0}, {-1, +1}, { 0, -1}, { 0, +1}, {+1, -1}, {+1,  0}, {+1, +1} };

#ifdef _DEBUG
#define debug(x) std::cout << "[" << __LINE__ << "] " << #x << ": " << x << std::endl
#else
#define debug(x)
#endif

template < class container > void concat(container& a, const container& b) {
    a.insert(std::end(a), std::begin(b), std::end(b));
}
std::vector<size_type> iota(const size_type n) {
    std::vector<size_type> I(n);
    std::iota(std::begin(I), std::end(I), 0);
    return I;
}
template < class container > std::vector<size_type> sort_idx(const container& a) {
    const size_type n = a.size();
    std::vector<size_type> I = iota(n);
    std::sort(std::begin(I), std::end(I), [&](size_type i, size_type j) { return a[i] < a[j] or (a[i] == a[j] and i < j); });
    return I;
}
template < class container, class compare > std::vector<size_type> sort_idx(const container& a, const compare& cmp) {
    const size_type n = a.size();
    std::vector<size_type> I = iota(n);
    std::sort(std::begin(I), std::end(I), [&](size_type i, size_type j) { return cmp(a[i], a[j]) or (a[i] == a[j] and i < j); });
    return std::move(I);
}

struct grid {
    using size_type = int;
    size_type H, W;
    grid(const size_type H, const size_type W) : H(H), W(W) {}
    bool contains(const size_type i, const size_type j) {
        return 0 <= i and i < H and 0 <= j and j < W;
    }
};

} // namespace macro

using namespace macro;
#line 3 "A.cpp"

int main() {
    int N = in();
    vector<int> A = in(N);

    vector<int> D;
    for(int n : A) {
        for(int i = 1; i * i <= n; i++) {
            if(n % i == 0) {
                D.push_back(i);
                D.push_back(n / i);
            }
        }
    }

    unique(D);
    i64 ans = 0;
    for(int d : D) if(d > 1) {
        i64 sum = 0;
        for(int n : A) if(n % d == 0) sum += n;
        chmax(ans, sum);
    }
    print(ans);
}
accuracy: 1
time_ms: 90
memory_kb: 3604
final_rank: 13

code_snippet: #include "bits/stdc++.h"

using namespace std;

using ll=long long;

void solve(){
    int n;cin>>n;
    vector<int>a(n);
    for (int i = 0; i < n; ++i) {
        cin>>a[i];
    }
    map<int,ll>mp;
    ll ans=0;
    auto Set=[&](int x,int y){
        if(x==1)return ;
        mp[x]+=y;
        ans=max(ans,mp[x]);
    };
    for(auto x:a){
        for(int i=1;i*i<=x;i++){
            if(x%i==0){
                Set(i,x);
                if(x/i!=i){
                    Set(x/i,x);
                }
            }
        }
    }
    cout<<ans<<"\n";
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;t=1;
    while(t--)solve();
}
accuracy: 1
time_ms: 60
memory_kb: 4792
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define per(i, n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define per2(i, l, r) for (int i = (r)-1; i >= (l); i--)
#define each(e, v) for (auto &e : v)
#define MM << " " <<
#define pb push_back
#define eb emplace_back
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;

template <typename T>
using minheap = priority_queue<T, vector<T>, greater<T>>;

template <typename T>
using maxheap = priority_queue<T>;

template <typename T>
bool chmax(T &x, const T &y) {
    return (x < y) ? (x = y, true) : false;
}

template <typename T>
bool chmin(T &x, const T &y) {
    return (x > y) ? (x = y, true) : false;
}

template <typename T>
int flg(T x, int i) {
    return (x >> i) & 1;
}

template <typename T>
void print(const vector<T> &v, T x = 0) {
    int n = v.size();
    for (int i = 0; i < n; i++) cout << v[i] + x << (i == n - 1 ? '\n' : ' ');
    if (v.empty()) cout << '\n';
}

template <typename T>
void printn(const vector<T> &v, T x = 0) {
    int n = v.size();
    for (int i = 0; i < n; i++) cout << v[i] + x << '\n';
}

template <typename T>
int lb(const vector<T> &v, T x) {
    return lower_bound(begin(v), end(v), x) - begin(v);
}

template <typename T>
int ub(const vector<T> &v, T x) {
    return upper_bound(begin(v), end(v), x) - begin(v);
}

template <typename T>
void rearrange(vector<T> &v) {
    sort(begin(v), end(v));
    v.erase(unique(begin(v), end(v)), end(v));
}

template <typename T>
vector<int> id_sort(const vector<T> &v, bool greater = false) {
    int n = v.size();
    vector<int> ret(n);
    iota(begin(ret), end(ret), 0);
    sort(begin(ret), end(ret), [&](int i, int j) { return greater ? v[i] > v[j] : v[i] < v[j]; });
    return ret;
}

template <typename S, typename T>
pair<S, T> operator+(const pair<S, T> &p, const pair<S, T> &q) {
    return make_pair(p.first + q.first, p.second + q.second);
}

template <typename S, typename T>
pair<S, T> operator-(const pair<S, T> &p, const pair<S, T> &q) {
    return make_pair(p.first - q.first, p.second - q.second);
}

template <typename S, typename T>
istream &operator>>(istream &is, pair<S, T> &p) {
    S a;
    T b;
    is >> a >> b;
    p = make_pair(a, b);
    return is;
}

template <typename S, typename T>
ostream &operator<<(ostream &os, const pair<S, T> &p) {
    return os << p.first << ' ' << p.second;
}

struct io_setup {
    io_setup() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout << fixed << setprecision(15);
    }
} io_setup;

const int inf = (1 << 30) - 1;
const ll INF = (1LL << 60) - 1;
// const int MOD = 1000000007;
const int MOD = 998244353;

template <typename T>
vector<T> divisors(const T &n) {
    vector<T> ret;
    for (T i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(begin(ret), end(ret));
    return ret;
}

template <typename T>
vector<pair<T, int>> prime_factor(T n) {
    vector<pair<T, int>> ret;
    for (T i = 2; i * i <= n; i++) {
        int cnt = 0;
        while (n % i == 0) cnt++, n /= i;
        if (cnt > 0) ret.emplace_back(i, cnt);
    }
    if (n > 1) ret.emplace_back(n, 1);
    return ret;
}

template <typename T>
bool is_prime(const T &n) {
    if (n == 1) return false;
    for (T i = 2; i * i <= n; i++) {
        if (n % i == 0) return false;
    }
    return true;
}

// 1,2,...,n のうち k と互いに素である自然数の個数
template <typename T>
T coprime(T n, T k) {
    vector<pair<T, int>> ps = prime_factor(k);
    int m = ps.size();
    T ret = 0;
    for (int i = 0; i < (1 << m); i++) {
        T prd = 1;
        for (int j = 0; j < m; j++) {
            if ((i >> j) & 1) prd *= ps[j].first;
        }
        ret += (__builtin_parity(i) ? -1 : 1) * (n / prd);
    }
    return ret;
}

vector<bool> Eratosthenes(const int &n) {
    vector<bool> ret(n + 1, true);
    if (n >= 0) ret[0] = false;
    if (n >= 1) ret[1] = false;
    for (int i = 2; i * i <= n; i++) {
        if (!ret[i]) continue;
        for (int j = i + i; j <= n; j += i) ret[j] = false;
    }
    return ret;
}

vector<int> Eratosthenes2(const int &n) {
    vector<int> ret(n + 1);
    iota(begin(ret), end(ret), 0);
    if (n >= 0) ret[0] = -1;
    if (n >= 1) ret[1] = -1;
    for (int i = 2; i * i <= n; i++) {
        if (ret[i] < i) continue;
        for (int j = i + i; j <= n; j += i) ret[j] = min(ret[j], i);
    }
    return ret;
}

int main() {
    int N;
    cin >> N;

    vector<ll> a(N), ps;
    rep(i, N) {
        cin >> a[i];
        each(e, prime_factor(a[i])) ps.eb(e.first);
    }

    rearrange(ps);
    ll ans = 0;

    each(e, ps) {
        ll tmp = 0;
        rep(i, N) {
            if (a[i] % e == 0) tmp += a[i];
        }
        chmax(ans, tmp);
    }

    cout << ans << '\n';
}
accuracy: 1
time_ms: 30
memory_kb: 3508
final_rank: 6

code_snippet: #include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define inf 1e9
#define INF 1e17
#define rep(i,n) for(int (i) =0; (i) < (n); (i)++)
#define all(x) (x).begin(), x.end();

vector<ll> find_divisor(ll N){
    vector<ll> A;
    for(int i=1;i*i<=N;i++){
        if(N%i==0){
            A.push_back(i);
            if(N/i!=i)A.push_back(N/i);
        }
    }
    return A;
}

int main(){
    ll N;
    cin>>N;
    vector<ll> A(N);
    set<ll> S;
    map<ll,ll> mp;
    rep(i,N)cin>>A[i];
    rep(i,N){
        vector<ll> D=find_divisor(A[i]);
        for(ll x:D){
            S.insert(x);
            mp[x]+=A[i];
        }
    }
    ll ans=0;
    auto itr=S.begin();
    while(itr!=S.end()){
        ll x=(*itr);
        if(x!=1)ans=max(ans,mp[x]);
        itr++;
    }
    cout<<ans<<endl;
}
accuracy: 1
time_ms: 190
memory_kb: 5852
final_rank: 16

code_snippet: // author: hanyu
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;

  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a.at(i);

  ll ans = 0;
  for (ll i = 2; i <= 40000; i++) {
    ll tmp = 0;
    for (int j = 0; j < n; j++) {
      if (a[j] % i == 0) tmp += a[j];
    }
    ans = max(ans, tmp);
  }

  for (auto i : a) {
    if (i <= 1) continue;
    ll tmp = 0;
    for (int j = 0; j < n; j++) {
      if (a[j] % i == 0) tmp += a[j];
    }
    ans = max(ans, tmp);
  }

  cout << ans << endl;
}
accuracy: 1
time_ms: 240
memory_kb: 3468
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int>a(n);
    map<int,long long>mp;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        for(int j = 1; j*j <= a[i]; j++) {
            if(a[i]%j == 0) {
                mp[j] += a[i];
                if(j*j != a[i]) mp[a[i]/j] += a[i];
            }
        }
    }
    long long mx = 0;
    for(auto i:mp) {
        if(i.first != 1) mx = max(mx,i.second);
    }
    cout << mx << endl;
}
accuracy: 1
time_ms: 60
memory_kb: 4784
final_rank: 7

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i, x) for(int i = 0; i < (x); i++)
using ll = long long;
#define all(v) v.begin(), v.end()

int main() {
	int n;
	cin >> n;
	// vector<ll> a(n);
	// for(auto&t : a) cin >> t;

	map<ll, ll> sum;
	rep(_, n) {
		ll a;
		cin >> a;
		const ll b = a;
		for(ll div = 2; div * div <= a; div++) {
			if(a % div == 0) {
				while(a % div == 0) a /= div;
				sum[div] += b;
			}
		}
		if(a > 1) sum[a] += b;
	}

	ll ans = 0;
	for(auto [a, b] : sum) {
		ans = max(ans, b);
	}

	cout << ans << '\n';
}
accuracy: 1
time_ms: 20
memory_kb: 3440
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    int N;
    ll ans = 0, s;
    cin >> N;
    vector<int> A(N), p;
    map<int,ll> mp;
    for(auto &&v: A){
        cin >> v;
        for(int j = 1; j * j <= v; j++){
            if(v % j == 0){
                mp[j] += v;
                if(j != v / j)mp[v / j] += v;
            }
        }
    }
    for(auto &&p:mp){
        if(p.first == 1)continue;
        ans = max(ans, p.second);
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 60
memory_kb: 4880
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    int N;
    ll ans = 0, s;
    cin >> N;
    vector<int> A(N);
    for(auto &&v: A)cin >> v;
    vector<bool> tb(100000);
    for(int i = 2; i < 100000; i++){
        if(tb[i])continue;
        for(int j = i; j < 100000; j += i){
            tb[j] = true;
        }
        s = 0;
        for(auto &&v:A){
            if(v % i == 0)s += v;
        }
        ans = max(ans, s);
    }
    map<int,long long> mp;
    for(auto &&v:A)mp[v] += v;
    for(auto &&p:mp){
        if(p.first <= 1)continue;
        ans = max(ans, p.second);
    }
    cout << ans << endl;
}
accuracy: 0.875
time_ms: 10
memory_kb: 3468
final_rank: 20