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

// macros
#define overload_rep(_1, _2, _3, name, ...) name
#define re_p(i, n) for(int i = 0; i < (n); ++i)
#define r_ep(i, x, y) for(int i = (x); i <= (y); ++i)
#define rep(...) overload_rep(__VA_ARGS__, r_ep, re_p)(__VA_ARGS__)
#define all(a) a.begin(), a.end()
#ifndef STOP_DEBUG
#define debug(...)\
    do { cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_cerr(__VA_ARGS__); cerr << noboolalpha; } while (0)
#else
#define debug(...)
#endif

// functions
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
void debug_cerr(){ cerr << '\n'; }
template<class Head, class... Tail>
void debug_cerr(Head head, Tail... tail){
    cerr << ' ' << head;
    debug_cerr(tail...);
}

// cin/cout setup
struct IoSetup{
    IoSetup(){
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} iosetup;

// libraries
template<class flow_t>
struct NetWork{
private:

    int V_sz;
    struct edge{
        int to, rev; flow_t cap;
        edge(int to, int rev, flow_t cap) : to(to), rev(rev), cap(cap) {}
    };
    vector<vector<edge>> graph;
    vector<int> level;
    vector<int> iter;

    void bfs(int start){
        fill(level.begin(), level.end(), -1);
        queue<int> que;
        level[start] = 0;
        que.push(start);
        while(!que.empty()){
            int v = que.front();
            que.pop();
            for(edge e : graph[v]){
                if(e.cap > flow_t(0) && level[e.to] < 0){
                    level[e.to] = level[v] + 1;
                    que.push(e.to);
                }
            }
        }
    }

    flow_t dfs(int now, int goal, flow_t flow){
        if(now == goal)return flow;
        for(int &i = iter[now]; i < graph[now].size(); i++){
            edge &e = graph[now][i];
            if(e.cap > flow_t(0) && level[now] < level[e.to]){
                flow_t tmp = dfs(e.to, goal, min<flow_t>(flow, e.cap));
                if(tmp > flow_t(0)){
                    e.cap -= tmp;
                    graph[e.to][e.rev].cap += tmp;
                    return tmp;
                }
            }
        }
        return flow_t(0);
    }

public:

    NetWork(int v_sz) : V_sz(v_sz), graph(v_sz), level(v_sz), iter(v_sz) {}

    void add_edge(int from, int to, flow_t cap){
        graph[from].push_back(edge(to, graph[to].size(), cap));
        graph[to].push_back(edge(from, graph[from].size() - 1, flow_t(0)));
    }

    flow_t dinic(int start, int goal){
        flow_t flow = 0;
        while(true){
            bfs(start);
            if(level[goal] < 0)return flow;
            fill(iter.begin(), iter.end(), 0);
            flow_t tmp;
            while((tmp = dfs(start, goal, flow_t(1e9))) > flow_t(0)){
                flow += tmp;
            }
        }
    }

};

// declarations
constexpr long long inf = 1ll << 40;

// solve
int main(){

    int N;
    cin >> N;

    NetWork<long long> net(N + 2);
    long long allsum = 0;
    rep(i, N){
        int A;
        cin >> A;
        if(A >= 0){
            allsum += A;
            net.add_edge(0, i + 1, A);
            net.add_edge(i + 1, N + 1, 0);
        } else {
            net.add_edge(0, i + 1, 0);
            net.add_edge(i + 1, N + 1, -A);
        }
    }

    rep(i, 1, N){
        for(int j = i + i; j <= N; j += i){
            net.add_edge(j, i, inf);
        }
    }

    cout << allsum - net.dinic(0, N + 1) << '\n';
    return 0;

}


Measured memory_bytes: 256