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, "from", int, "to", long, "cap", int, "rev");

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

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

    void addEdge(int u, int v, long cap) {
        adj[u] ~= Edge(u, v, cap, adj[v].length.to!int);
        adj[v] ~= Edge(v, u, 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 - 1] >= 0) {
            addEdge(i, n + 1, a[i - 1]);
        }
        else {
            addEdge(0, i, -a[i - 1]);
        }
    }

    debug {
        writeln(adj);
    }

    long ans = a.filter!"a > 0".sum(0L);

    ans -= EdmondsKarp(adj, 0, n + 1);

    writeln(ans);
}

long EdmondsKarp(Edge[][] adj, int s, int t) {
    int n = adj.length.to!int;
    long F;

    while (true) {
        auto q = Queue!(int)(n);
        q.push(s);

        auto pred = new Edge*[](n);
        pred[] = null;

        while (!q.empty && pred[t] is null) {
            auto cur = q.front;
            q.pop();

            debug {
                //writefln("cur:%d", cur);
            }

            foreach (ref e ; adj[cur]) {
                debug {
                    //writeln(&e);
                }
                if (pred[e.to] is null && e.to != s && e.cap > 0) {
                    pred[e.to] = &e;
                    q.push(e.to);
                }
            }
        }

        debug {
            writeln(pred);
        }

        if (!(pred[t] is null)) {
            long df = inf;

            for (auto e = pred[t]; !(e is null); e = pred[e.from]) {
                //writefln("e.cap:%d", e.cap);
                df = min(df, e.cap);
            }

            debug {
                writeln("a");
            }

            for (auto e = pred[t]; !(e is null); e = pred[e.from]) {
                e.cap -= df;
                adj[e.to][e.rev].cap += df;
            }

            debug {
                writeln(df);
            }

            F += df;
        }

        if (pred[t] is null) 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 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);
        }
    }
}

Measured memory_bytes: 380