import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

immutable inf = 10L^^16;
alias Edge = Tuple!(int, "to", long, "flow", long, "cap", int, "rev");

void main() {
    int n;
    scan(n);
    auto a = readln.split.to!(int[]);
    a = [0] ~ a;

    auto adj = new Edge[][](n + 2, 0);

    void addEdge(int u, int v, long cap) {
        adj[u] ~= Edge(v, 0, cap, adj[v].length.to!int);
        adj[v] ~= Edge(u, 0, 0, adj[u].length.to!int - 1);
    }

    foreach (i ; 1 .. n + 1) {
        foreach (j ; iota(2*i, n + 1, i)) {
            addEdge(i, j, inf);
        }

        if (a[i] >= 0) {
            addEdge(i, n + 1, a[i]);
        }
        else {
            addEdge(0, i, -a[i]);
        }
    }

    long ans = a.filter!"a > 0".sum(0L) - Dinic(adj, 0, n + 1);

    writeln(ans);
}

long Dinic(Edge[][] adj, int s, int t) {
    int n = adj.length.to!int;
    int[] level = new int[](n);
    int[] prog = new int[](n);
    auto q = Queue!(int)(n);

    bool bfs() {
        level[] = -1;
        level[s] = 0;
        q.clear();
        q.push(s);

        while (!q.empty) {
            auto u = q.front;
            q.pop;

            foreach (e ; adj[u]) {
                if (level[e.to] == -1 && e.cap - e.flow > 0) {
                    level[e.to] = level[u] + 1;
                    q.push(e.to);
                }
            }
        }

        return level[t] != -1;
    }

    long dfs(int u, long f) {
        if (u == t) return f;

        for (; prog[u] < adj[u].length; prog[u]++) {
            auto e = &adj[u][prog[u]];

            if (level[u] + 1 == level[e.to] && e.flow < e.cap) {
                long d = dfs(e.to, min(f, e.cap - e.flow));

                if (d > 0) {
                    e.flow += d;
                    adj[e.to][e.rev].flow -= d;
                    return d;
                }
            }
        }

        return 0;
    }

    long F;

    while (bfs()) {
        prog[] = 0;

        while (true) {
            auto df = dfs(s, inf);

            if (df) F += df;
            else break;
        }
    }

    return F;
}


struct Queue(T) {
    private {
        int N, head, tail;
        T[] data;
    }

    this (int n) {
        N = n + 1;
        data = new T[](N);
    }

    bool empty() {
        return head == tail;
    }

    bool full() {
        return (tail + 1) % N == head;
    }

    T front() {
        return data[head];
    }

    void push(T x) {
        assert(!full);
        data[tail++] = x;
        tail %= N;
    }

    void pop() {
        assert(!empty);
        head++;
        head %= N;
    }

    void clear() {
        head = tail = 0;
    }
}

void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}