#include <bits/stdc++.h>
using namespace std;

template <typename T>
class Maxflow
{
    struct edge
    {
        int to;
        T cap;
        int rev;
    };
    std::vector<std::vector<edge>> edges;
    std::vector<int> level;
    std::vector<int> iter;
    std::vector<int> used;

    void bfs(int s)
    {
        level = std::vector<int>(edges.size(), -1);
        std::queue<int> q;
        level[s] = 0;
        q.push(s);
        while (!q.empty())
        {
            int v = q.front();
            q.pop();
            for (edge &e : edges[v])
            {
                if (e.cap > 0 && level[e.to] < 0)
                {
                    level[e.to] = level[v] + 1;
                    q.push(e.to);
                }
            }
        }
    }

    T dfs_d(int v, int goal, T f)
    {
        if (v == goal)
            return f;
        for (int &i = iter[v]; i < (int)edges[v].size(); i++)
        {
            edge &e = edges[v][i];
            if (e.cap > 0 && level[v] < level[e.to])
            {
                T d = dfs_d(e.to, goal, std::min(f, e.cap));
                if (d > 0)
                {
                    e.cap -= d;
                    edges[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

    T dfs_ff(int v, int goal, T f)
    {
        if (v == goal)
            return f;
        used[v] = true;
        for (int i = 0; i < (int)edges[v].size(); i++)
        {
            edge &e = edges[v][i];
            if (e.cap > 0 && !used[e.to])
            {
                T d = dfs_ff(e.to, goal, std::min(f, e.cap));
                if (d > 0)
                {
                    e.cap -= d;
                    edges[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

  public:
    Maxflow(int N) { edges.resize(N); }
    void add_edge(int from, int to, T capacity)
    {
        edges[from].push_back(edge{to, capacity, (int)edges[to].size()});
        edges[to].push_back(edge{from, (T)0, (int)edges[from].size() - 1});
    }

    T Dinic(int s, int t)
    {
        constexpr T INF = std::numeric_limits<T>::max();
        T flow = 0;
        while (true)
        {
            bfs(s);
            if (level[t] < 0)
                return flow;
            iter = std::vector<int>(edges.size(), 0);
            T f;
            while ((f = dfs_d(s, t, INF)) > 0)
                flow += f;
        }
    }

    T FF(int s, int t)
    {
        constexpr T INF = std::numeric_limits<T>::max();
        T flow = 0;
        while (true)
        {
            used = std::vector<int>(edges.size(), 0);
            T f = dfs_ff(s, t, INF);
            if (f == 0)
                return flow;
            flow += f;
        }
    }
};

int main()
{
    int N;
    cin >> N;
    Maxflow<long long> graph(N + 2);
    vector<long long> a(N + 1);
    long long sum = 0;
    for (int i = 1; i <= N; i++)
    {
        for (int j = i; j <= N; j += i) graph.add_edge(i, j, 1E9*100LL);
        cin >> a[i];
        if (a[i] >= 0)
        {
            graph.add_edge(i, N+1, a[i]);
            sum += a[i];
        }
        else graph.add_edge(0, i, -a[i]);
    }

    cout << sum - graph.Dinic(0, N+1) << endl;
    return 0;
}

Measured memory_bytes: 256