#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

template <class T>
class EdgeBase
{
public:
    int to, rev;
    T cap;
    EdgeBase(){};
    EdgeBase(int to0, T cap0){to = to0; cap = cap0;}
    EdgeBase(int to0, T cap0, int rev0){to = to0; cap = cap0; rev = rev0;}
};
typedef EdgeBase<long long> Edge;

template<class T>
T maxFlow(const vector<vector<EdgeBase<T> > >& edges0, int source, int sink)
{
    static const T INF = numeric_limits<T>::max();
    static const T EPS = static_cast<T>(1.0e-10);
    static vector<vector<EdgeBase<T> > > edges;
    static vector<unsigned> index;
    static vector<int> level;

    class Func{
    public:
        static void bfs(int s){
            int n = edges.size();
            level.assign(n, -1);
            queue<int> q;
            level[s] = 0;
            q.push(s);
            while(!q.empty()){
                int v = q.front();
                q.pop();
                for(auto& e : edges[v]){
                    if(e.cap > EPS && level[e.to] < 0){
                        level[e.to] = level[v] + 1;
                        q.push(e.to);
                    }
                }
            }
        }
        static T dfs(int s, int t, T f){
            if(s == t)
                return f;
            for(auto& e : edges[s]){
                if(e.cap > EPS && level[s] < level[e.to]){
                    T g = dfs(e.to, t, min(f, e.cap));
                    if(g > EPS){
                        e.cap -= g;
                        edges[e.to][e.rev].cap += g;
                        return g;
                    }
                }
            }
            return 0;
        }
    };

    if(source == sink)
        return INF;

    int n = edges0.size();
    edges.assign(n, vector<EdgeBase<T> >());
    for(int i=0; i<n; ++i){
        for(const auto& e : edges0[i]){
            edges[i].push_back(EdgeBase<T>(e.to, e.cap, edges[e.to].size()));
            edges[e.to].push_back(EdgeBase<T>(i, 0, edges[i].size()-1));
        }
    }

    T ret = 0;
    for(;;){
        Func::bfs(source);
        if(level[sink] < 0)
            return ret;
        index.assign(n, 0);
        for(;;){
            T f = Func::dfs(source, sink, INF);
            if(f == 0)
                break;
            ret += f;
        }
    }
}


int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; ++i)
        cin >> a[i];

    int source = 0;
    int sink = n + 1;
    vector<vector<Edge> > edges(n+2);
    long long ans = 0;
    for(int i=1; i<=n; ++i){
        edges[source].push_back(Edge(i, max(0, a[i-1])));
        edges[i].push_back(Edge(sink, max(0, -a[i-1])));
        ans += max(0, a[i-1]);
        for(int j=i*2; j<=n; j+=i)
            edges[j].push_back(Edge(i, LLONG_MAX/2));
    }

    ans -= maxFlow(edges, source, sink);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256