#include <bits/stdc++.h>
//#include <chrono>
//#pragma GCC optimize("Ofast")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second

using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

ll N,M,H,W,Q,K,A,B;
string S;
typedef pair<ll, ll> P;
const ll INF = (1LL<<58);

template<class T> bool chmin(T &a, const T &b){
    if(a > b) {a = b; return true;}
    else return false;
}
template<class T> bool chmax(T &a, const T &b){
    if(a < b) {a = b; return true;}
    else return false;
}

struct edge{
    int to, rev;
    ll cap;
    edge(){}
    edge(int a, ll b, int c){
        to = a;
        cap = b;
        rev = c;
    }
};
using ve = vector<edge>;

class submodular_solver {
public:
    bool edge_unite;
    //With unite : worst time complexity of adding edge (total) : O(|E||V|)
    //However, time complexity of dinic is O(|E||V|^2) (worst)
    unsigned int n, s, t;
    ll max_flow_default; //for submodular_solver
    vector<ve> G;
    submodular_solver(unsigned int _n, unsigned int _s, unsigned int _t, bool unite = true)
    : edge_unite(unite), n(_n), G(_n), s(_s), t(_t), max_flow_default(0){}

    //min_cut_solver
    void add_edge(int from, int to, ll cap, bool directed = true) {
        if(cap == 0 || from == -1 || to == -1) return;
        if(edge_unite){
            for(edge &e : G[from]){
                if(e.to == to){
                    e.cap += cap;
                    if(!directed) G[e.to][e.rev].cap += cap;
                    return;
                }
            }
        }
        G[from].emplace_back(to, cap, (int) G[to].size());
        G[to].emplace_back(from, directed ? 0 : cap, (int) G[from].size() - 1);
    }

    void bfs(vector<int> &level) {
        queue<int> que;
        level[s] = 0;
        que.push(s);
        while (!que.empty()) {
            int v = que.front();
            que.pop();
            for (edge &e : G[v]) {
                if (e.cap > 0 && chmin(level[e.to], level[v] + 1)) {
                    que.push(e.to);
                }
            }
        }
    }

    ll dfs(int v, ll f, vector<int> &level, vector<int> &iter) {
        if (v == t) return f;
        for (int &i = iter[v]; i < G[v].size(); ++i) {
            edge &e = G[v][i];
            if (e.cap > 0 && level[v] < level[e.to]) {
                ll d = dfs(e.to, min(f, e.cap), level, iter);
                if (d > 0) {
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

    ll dinic(int _s = -1, int _t = -1) {
        if(_s != -1) s = _s;
        if(_t != -1) t = _t;
        ll res(max_flow_default);
        for (;;) {
            vector<int> level(n, INT_MAX), iter(n, 0);
            bfs(level);
            if (level[t] == INT_MAX) return res;
            ll f;
            while ((f = dfs(s, INF, level, iter)) > 0) res += f;
        }
    }

    vector<bool> group_T(){
        //output : if v is in T (including "goal" = t), return true.
        if(s == -1) {
            vector<bool> temp_res(0);
            return temp_res;
        }
        vector<int> level(n, INT_MAX);
        bfs(level);
        vector<bool> res(n);
        rep(i, n) res[i] = level[i] == INT_MAX;
        return res;
    }

    //submodular_solver
    //definition
    //x_i = 0 : vertex i is in S(including "start" = s)
    //x_i = 1 : vertex i is in T(including "goal" = t)
    void add_theta_v(int v, ll zero, ll one) {
        if(zero < one){
            //To add "one - zero" when v is in T, s-v edge must be added.
            max_flow_default += zero;
            add_edge(s, v, one - zero);
        }else{
            max_flow_default += one;
            add_edge(v, t, zero - one);
        }
    }

    void add_theta(vec zero = {}, vec one = {}){
        int zero_sz = zero.size(), one_sz = one.size();
        rep(i, n){
            if(zero_sz <= i && one_sz <= i) return;
            add_theta_v(i, zero_sz <= i ? 0LL : zero[i], one_sz <= i ? 0LL : one[i]);
        }
    }

    void add_phi_ij(int i, int j, ll zero_zero, ll zero_one, ll one_zero, ll one_one){
        //To add phi_ij : (0,0), (0,1), (1,0), (1,1)
        max_flow_default += zero_zero;
        add_theta_v(i, 0, one_zero - zero_zero);
        add_theta_v(j, 0, one_one - one_zero);
        ll new_zero_one = zero_one + one_zero - (zero_zero + one_one); //more than zero (because of the nature of submodular)
        assert(new_zero_one >= 0);
        add_edge(i, j, new_zero_one);
    }

};

using mflow = submodular_solver;

int main() {
    cin>>N;
    vec a(N);
    rep(i, N) {cin>>a[i]; a[i] = -a[i];}
    const int start = N, goal = N + 1;
    submodular_solver graph(N + 2, start, goal);
    graph.add_theta(a);
    rep(i, N){
        for(int j = (i + 1) * 2; j <= N; j += i + 1){
            graph.add_phi_ij(i, j - 1, 0, 0, INF / N, 0); //流量が無駄に増えるので注意
            //graph.add_edge(j - 1, i, INF);
        }
    }
    cout<<- graph.dinic()<<endl;
}


Measured memory_bytes: 3660