#include <bits/stdc++.h>
#define FI(i, a, b) for (int i = (a); i <= (b); i++)
#define FD(i, b, a) for (int i = (b); i >= (a); i--)
#define len(a) int((a).size())
using namespace std;
using LL = long long;
using PII = pair<int, int>;

template <class T> struct MaxFlowGraph {
    struct Edge {
        int u, v;
        T c, f;
    };
    const T eps = (T)1e-9;
    vector<Edge> E;
    vector<vector<int>> G;
    vector<int> P, D;
    int n, src, sink;
    T flow;

    MaxFlowGraph(int n, int src, int sink) : n(n), src(src), sink(sink) {
        assert(0 <= src && src < n && 0 <= sink && sink < n && src != sink);
        G.resize(n);
        P = D = vector<int>(n);
        flow = T();
    }

    void clearFlow() {
        for (auto &e : E) {
            e.f = T();
        }
        flow = T();
    }
    void addEdge(int u, int v, T forward_cap, T backward_cap) {
        assert(0 <= u && u < n && 0 <= v && v < n);
        G[u].push_back(E.size());
        E.push_back({u, v, forward_cap, T()});
        G[v].push_back(E.size());
        E.push_back({v, u, backward_cap, T()});
    }

    bool expath() {
        fill(D.begin(), D.end(), -1);
        queue<int> Q;
        Q.push(sink);
        D[sink] = 0;
        while (!Q.empty()) {
            int u = Q.front();
            Q.pop();
            for (int id : G[u]) {
                const Edge &e = E[id];
                const Edge &back = E[id ^ 1];
                if (back.c - back.f > eps && D[e.v] == -1) {
                    D[e.v] = D[e.u] + 1;
                    if (e.v == src) {
                        return true;
                    }
                    Q.push(e.v);
                }
            }
        }
        return false;
    }

    T dfs(int u, T w) {
        if (u == sink) {
            return w;
        }
        for (int &i = P[u]; i < G[u].size(); i++) {
            int id = G[u][i];
            const Edge &e = E[id];
            if (e.c - e.f > eps && D[e.v] == D[e.u] - 1) {
                T t = dfs(e.v, min(e.c - e.f, w));
                if (t > eps) {
                    E[id].f += t;
                    E[id ^ 1].f -= t;
                    return t;
                }
            }
        }
        return T();
    }

    T maxFlow() {
        while (expath()) {
            fill(P.begin(), P.end(), 0);
            T tot = T();
            while (true) {
                T add = dfs(src, numeric_limits<T>::max());
                if (add <= eps) {
                    break;
                }
                tot += add;
            }
            if (tot <= eps) {
                break;
            }
            flow += tot;
        }
        return flow;
    }
    vector<bool> minCut() {
        maxFlow();
        vector<bool> R(n);
        for (int i = 0; i < n; i++) {
            R[i] = (D[i] != -1);
        }
        return R;
    }
    void reduce() {
        for (auto &e : E) {
            e.c -= e.f;
        }
    }
};

const int N = 105;
const int INF = numeric_limits<int>::max();
int n;
auto g = MaxFlowGraph<LL>(N, 101, 102);

int main() {
    scanf("%d", &n);
    LL tot = 0;
    FI(i, 1, n) {
        int x;
        scanf("%d", &x);
        if (x > 0) {
            tot += x;
            g.addEdge(i, 102, x, 0);
        } else if (x < 0) {
            g.addEdge(101, i, -x, 0);
        }
    }
    FI(i, 1, n) {
        for (int j = 2 * i; j <= n; j += i) {
            g.addEdge(i, j, INF, 0);
        }
    }
    printf("%lld\n", tot - g.maxFlow());
}

Measured memory_bytes: 256