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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define FORI(i,v) for (auto i = v.begin(); i != v.end(); i++)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)
#define YES(b) cout << ((b) ? "YES" : "NO") << endl
#define Yes(b) cout << ((b) ? "Yes" : "No") << endl
#define DOUBLE(d) cout << fixed << setprecision(15) << (d) << endl

template<typename T, bool directed, T inf> class Dinic {
private:
    struct Edge {
        int to; T cap; int rev;
        Edge(int to, T cap, int rev) : to(to), cap(cap), rev(rev) {}
    };
 
    vector<int> level, iter;
 
    void init(int n) {
        G = vector<vector<Edge>>(n);
        level = vector<int>(n);
        iter = vector<int>(n);
    }
 
    void bfs(int s) {
        fill(ALL(level), -1);
        level[s] = 0;
        queue<int> que;
        que.push(s);
        while (!que.empty()) {
            int n = que.front(); que.pop();
            for (auto &&e : G[n]) if (e.cap > T(0) && level[e.to] < 0) {
                level[e.to] = level[n] + 1;
                que.push(e.to);
            }
        }
    }
 
    T dfs(int s, int t, T f) {
        if (s == t) return f;
        for (int &i = iter[s]; i < G[s].size(); i++) {
            Edge& e = G[s][i];
            if (e.cap > T(0) && level[s] < level[e.to]) {
                T d = dfs(e.to, t, min(f, e.cap));
                if (d == T(0)) continue;
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
        return T(0);
    }
 
public:
    Dinic() {}
    Dinic(int n) { init(n); }
 
    vector<vector<Edge>> G;
    void add(int from, int to, T cap) {
        if (!cap) return;
        G[from].push_back(Edge(to, cap, G[to].size()));
        G[to].push_back(Edge(from, (directed ? 0 : cap), G[from].size()-1));
    }
 
    T solve(int s, int t, T lim = inf) {
        T ret(0);
        while (1) {
            bfs(s);
            if (level[t] < 0 || lim == 0) return ret;
            fill(ALL(iter), 0);
            while (1) {
                T f = dfs(s, t, lim);
                if (f == T(0)) break;
                ret += f;
                lim -= f;
            }
        }
    }
};

const int MAX = 111;
const ll INF = 1ll<<62;

int N;
ll A[MAX];

ll solve() {
    Dinic<ll, true, INF> dinic(N+2);
    int S = N, T = N+1;

    ll mx = 0;
    REP (i, N) {
        if (A[i] >= 0) {
            mx += A[i];
            dinic.add(S, i, A[i]);
        } else {
            dinic.add(i, T, -A[i]);
        }
    }
    REP (j, N) REP (i, N) if ((i+1)%(j+1) == 0) {
        dinic.add(i, j, INF);
    }

    return mx - dinic.solve(S,T);
}

int main() {
    cin >> N;
    REP (i, N) cin >> A[i];
    cout << solve() << endl;
}

Measured memory_bytes: 256