#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<<60);

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;
    vector<ve> G;
    submodular_solver(unsigned int _n, bool unite = true) : edge_unite(unite), n(_n), G(_n){}

    void add_edge(int from, int to, ll cap, bool directed = true) {
        if(edge_unite){
            for(edge &e : G[from]){
                if(e.to == to){
                    e.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(int s, 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, int t, 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, t, 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, int t) {
        ll res = 0;
        int sz = G.size();
        for (;;) {
            vector<int> level(sz, INT_MAX), iter(sz, 0);
            bfs(s, level);
            if (level[t] == INT_MAX) return res;
            ll f;
            while ((f = dfs(s, t, INF, level, iter)) > 0) res += f;
        }
    }
};

using subM = submodular_solver;

int main() {
    cin>>N;
    vec a(N);
    rep(i, N) cin>>a[i];
    subM graph(N + 2, true);
    const int start = N, goal = N + 1;
    ll res(0);
    rep(i, N){
        if(a[i] >= 0){
            res += -a[i];
            graph.add_edge(start, i, a[i]);
        }else{
            graph.add_edge(i, goal, -a[i]);
        }
    }
    rep(i, N){
        for(int j = (i + 1) * 2; j <= N; j += i + 1){
            graph.add_edge(j - 1, i, INF);
        }
    }
    res += graph.dinic(start, goal);
    cout<<-res<<endl;
}


Measured memory_bytes: 3636