#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std;
using lint = long long;
using ld = long double;

// 諸宣言
using Weight = lint;
using Flow = lint;
struct Edge {
    int src, dst;
    Weight weight;
    Flow cap;
    Edge() : src(0), dst(0), weight(0) {}
    Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
    Edge(int s, int d, Weight w, Flow c) : src(s), dst(d), weight(w), cap(c) {}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;

void add_edge(Graph &g, int a, int b, Weight w = 1, Flow c = 1) {
    g[a].emplace_back(a, b, w, c);
    g[b].emplace_back(b, a, w, c);
}
void add_arc(Graph &g, int a, int b, Weight w = 1, Flow c = 1) {
    g[a].emplace_back(a, b, w, c);
}

// フォード・ファルカーソン法  O(fE+V^2)
struct ford_fulkerson {
    using Matrix = vector<vector<Flow>>;
    int n, t;
    vector<int> vis;
    vector<vector<Flow>> cap, flow;
    vector<vector<int>> g;
    const Flow INF;
    ford_fulkerson(int n)
        : n(n),
          cap(n, vector<Flow>(n)),
          flow(n, vector<Flow>(n)),
          g(n, vector<int>()),
          INF(numeric_limits<Flow>::max() / 8) {}
    ford_fulkerson(const Graph &graph) : ford_fulkerson(graph.size()) {
        for (int i = 0; i < n; ++i)
            for (auto &e : graph[i]) add_edge(e.src, e.dst, e.cap);
    }
    void add_edge(int u, int v, Flow c) {
        cap[u][v] += c;
        cap[v][u] += c;
        flow[v][u] += c;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    Flow solve(int s, int t) {
        this->t = t;
        Flow res = 0, aug = 1;
        while (aug > 0) {
            vis.assign(n, false);
            res += (aug = augment(s, INF));
        }
        return res;
    }
    Flow augment(const int &v, const Flow &lim) {
        vis[v] = true;
        if (v == t) return lim;
        for (const int &d : g[v]) {
            if (vis[d] || flow[v][d] == cap[v][d]) continue;
            Flow aug = augment(d, min(lim, cap[v][d] - flow[v][d]));
            flow[v][d] += aug;
            flow[d][v] -= aug;
            if (aug > 0) return aug;
        }
        return 0;
    }
};

int main(void) {
    int n;
    cin >> n;
    lint sum = 0;
    vector<int> a(n + 1);
    repeat_from_to (i, 1, n) {
        cin >> a[i];
        (a[i] > 0 ? sum += a[i] : sum += 0);
    }
        
    const int s = 0;
    const int t = n + 1;
    Graph g(n + 2);
    
    // s が残す側，t が割る側
    repeat_from_to (i, 1, n) {
        if (a[i] > 0) {
            add_arc(g, s, i, 1, a[i]);
        }
        else {
            add_arc(g, i, t, 1, -a[i]);
        }
    }
    
    // 倍数約数関係は両方残すか両方割るか
    const lint INF = numeric_limits<lint>::max() / 100;
    repeat_from_to (i, 1, n) {
        repeat_from_to (j, i + 1, n) {
            if (j % i == 0) {
                add_arc(g, j, i, 1, INF);
            }
        }
    }
    
    ford_fulkerson ff(g);
    cout << sum - ff.solve(s, t) << endl;
}

Measured memory_bytes: 384