#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

#define YES(condition) if(condition) cout << "YES" << endl; else cout << "NO" << endl
#define Yes(condition) if(condition) cout << "Yes" << endl; else cout << "No" << endl
#define POSS(condition) if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl
#define Poss(condition) if(condition)cout << "Possible" << endl; else cout << "Impossible" << endl
#define First(condition) if(condition)cout << "First" << endl; else cout << "Second" << endl
long power(long base, long exponent, long mod){ if(exponent % 2){ return power(base, exponent - 1, mod) * base % mod; }else if(exponent){ long root_ans = power(base, exponent / 2, mod); return root_ans * root_ans % mod; }else{ return 1; }}

template< typename T >
struct Dinic
{
    struct edge
    {
        int to;
        T cap;
        int rev;
    };
    
    const T INF;
    vector< vector< edge > > graph;
    vector< T > min_cost;
    vector< int > iter;
    
    Dinic(int n) : INF(numeric_limits< T >::max())
    {
        graph.resize(n);
    }
    
    void add_edge(int from, int to, T cap)
    {
        graph[from].push_back((edge) {to, cap, (int) graph[to].size()});
        graph[to].push_back((edge) {from, 0, (int) graph[from].size() - 1});
    }
    
    bool bfs(int s, int t)
    {
        min_cost.assign(graph.size(), -1);
        queue< int > que;
        min_cost[s] = 0;
        que.push(s);
        while(!que.empty()) {
            int p = que.front();
            que.pop();
            for(auto &e : graph[p]) {
                if(e.cap > 0 && min_cost[e.to] == -1) {
                    min_cost[e.to] = min_cost[p] + 1;
                    que.push(e.to);
                }
            }
        }
        return (min_cost[t] != -1);
    }
    
    T dfs(int idx, const int t, T flow)
    {
        if(idx == t) return (flow);
        for(int &i = iter[idx]; i < graph[idx].size(); i++) {
            edge &e = graph[idx][i];
            if(e.cap > 0 && min_cost[idx] < min_cost[e.to]) {
                T d = dfs(e.to, t, min(flow, e.cap));
                if(d > 0) {
                    e.cap -= d;
                    graph[e.to][e.rev].cap += d;
                    return (d);
                }
            }
        }
        return (0);
    }
    
    T max_flow(int s, int t)
    {
        T flow = 0;
        while(bfs(s, t)) {
            iter.assign(graph.size(), 0);
            T f = 0;
            while((f = dfs(s, t, INF)) > 0) {
                flow += f;
            }
        }
        return (flow);
    }
};

int main(){
    int N;
    cin >> N;
    Dinic<long> graph(N + 2);
    long ans = 0;
    for(int i = 0; i < N; i++){
        long num;
        cin >> num;
        if(num > 0){
            ans += num;
            graph.add_edge(N, i, 0);
            graph.add_edge(i, N + 1, num);
        }else if(num < 0){
            graph.add_edge(N, i, -num);
            graph.add_edge(i, N + 1, 0);
        }
    }
    for(int i = 0; i < N; i++){
        for(int j = (i + 1) * 2; j <= N; j += i + 1){
            graph.add_edge(i, j - 1, 1e15);
        }
    }
    cout << ans - graph.max_flow(N, N + 1) << endl;
}


Measured memory_bytes: 256