#include <bits/stdc++.h>

using namespace std;

#define whole(xs) (xs).begin(), (xs).end()

namespace {
    typedef long long ll;
    int N;
    vector<ll> A;
    void input() {
        cin >> N;
        A.resize(N);
        for (int i = 0; i < N; i++) cin >> A[i];
    }

    template<typename T>
    struct Network {
        static const T INF = numeric_limits<T>::max() >> 12;
        struct Edge {
            int from, to;
            T cap;
            Edge* rev;
            Edge(int from, int to, T cap) :
                from(from), to(to), cap(cap) {}
        };
        vector<Edge*> edges, rev_edges;
        vector<vector<Edge*>> graph;
        Network(int N) : graph(N, vector<Edge*>()) {}
        ~Network() { 
            for (auto e : edges) delete(e);
            for (auto r : rev_edges) delete(r);
        }
        void addEdge(int s, int t, T cap) {
            auto e = new Edge(s, t, cap);
            auto r = new Edge(t, s, 0);
            edges.push_back(e); rev_edges.push_back(r);
            e->rev = r; r->rev = e;
            graph[s].push_back(e); graph[t].push_back(r);
        }
        T maxFlow(int s, int t) {
            const int N = graph.size();
            vector<int> label(N, 0); label[s] = N;
            vector<T> excess(N, 0);
            int level = 0;
            for (auto e : graph[s]) {
                auto gamma = e->cap;
                e->cap = 0;
                e->rev->cap = gamma;
                excess[e->from] -= gamma;
                excess[e->to] += gamma;
            }
            vector<vector<int>> L(2*N, vector<int>()); {
                for (int i = 0; i < N; i++) if (i != s and i != t and excess[i] > 0) {
                    L[0].push_back(i);
                }
            }
            auto push = [&](Edge* e) {
                auto gamma = min(excess[e->from], e->cap);
                if (gamma == 0) return;
                e->cap -= gamma;
                e->rev->cap += gamma;
                int u = e->from; int v = e->to;
                if (u != s and u != t and excess[u] == gamma) {
                    assert(not L[label[u]].empty());
                    L[label[u]].pop_back();
                }
                if (v != s and v != t and excess[v] == 0) L[label[v]].push_back(v);
                excess[u] -= gamma; excess[v] += gamma;
            };
            auto relabel = [&](int v) {
                assert(not L[level].empty());
                L[level].pop_back();
                label[v] = 1<<28;
                for (auto e : graph[v]) {
                    if (e->cap <= 0) continue;
                    int w = e->to;
                    label[v] = min(label[v], label[w] + 1);
                };
                L[label[v]].push_back(v);
                level = label[v];
            };
            while (level >= 0) {
                if (L[level].empty()) { level--; continue; }
                auto v = L[level].back();
                bool used = false;
                for (auto e : graph[v]) {
                    if (label[e->from] == label[e->to] + 1 and e->cap > 0) {
                        used = true;
                        push(e);
                    }
                }
                if (not used) {
                    relabel(v);
                }
            }
            return excess[t];
        }
    };

    void solve() {
        Network<ll> network(N + 2);
        for (int i = 0; i < N; i++) {
            int k = i + 1;
            ll a = A[i];
            if (a < 0) {
                network.addEdge(0, k, -a);
            } else if (a > 0) {
                network.addEdge(k, N + 1, a);
            }
        }
        for (int i = 1; i <= N; i++) {
            for (int j = i + i; j <= N; j += i) {
                network.addEdge(i, j, 1LL<<48);
            }
        }
        cout << accumulate(whole(A), 0LL, [&](ll acc, ll x){ return acc + max(0LL, x); }) - network.maxFlow(0, N + 1) << endl;
    }
}

int main() {
    input(); solve();
}

Measured memory_bytes: 256