#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
#include <ctime>
#include <unordered_map>
#include <iomanip>
#include <complex>
#include <cassert>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define deb(a) cerr<< #a << "= " << (a)<<"\n";

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long double ld;
typedef complex<double> base;
typedef vector<ll> vi;
typedef pair<int,int> pii;

template<class T> ostream& operator<<(ostream& stream, const vector<T> v){ stream << "[ "; for (int i=0; i<(int)v.size(); i++) stream << v[i] << " "; stream << "]"; return stream; }
ll fpow(ll x, ll p, ll m){ll r=1; for (;p;p>>=1){ if (p&1) r=r*x%m; x=x*x%m; } return r;}
int gcd(int a, int b){ if (!b) return a; return gcd(b,a%b);}
ll gcd(ll a, ll b){ if (!b) return a; return gcd(b,a%b);}

ll N,a[110];

const ll inf = (1LL<<40);

struct MaxFlow{
    vector<vi> c,f,g;
    int s,t,N;
    vi ptr,d;
    MaxFlow(int N, int s, int t){
        this->N = N, this->s = s, this->t = t;

        c.resize(N),f.resize(N),g.resize(N);
        for (int i=0; i<N; i++)
            c[i].resize(N),f[i].resize(N);

    }

    ll getmaxflow(){
        ll res=0;
        for (int i=0; i<N; i++)
            fill(all(f[i]),0);

        while (bfs()){
            ptr.clear();
            ptr.resize(N,0);

            while (ll pushed=dfs(s,inf))
                res+=pushed;


        }

        return res;
    }

    ll dfs(int nod, ll flow){
        if (!flow) return 0;
        if (nod==t) return flow;

        for (ll &i=ptr[nod]; i<g[nod].size(); i++){
            int nxt=g[nod][i];
            if (d[nxt]!=d[nod]+1) continue;

            ll pushed=dfs(nxt,min(flow,c[nod][nxt]-f[nod][nxt]));
            if (pushed){
                f[nod][nxt]+=pushed;
                f[nxt][nod]-=pushed;
                return pushed;
            }
        }

        return 0;
    }

    void add_uedge(int from, int to, ll cap){
        g[from].pb(to);
        g[to].pb(from);
        c[from][to]+=cap;
    }

    void add_bedge(int from, int to, ll cap){
        c[from][to]+=cap;
        c[to][from]+=cap;
        g[from].pb(to);
        g[to].pb(from);
    }
    void print(){
        cout << N << "\n";
        for (int i=0; i<N; i++, cout << "\n")
            for (int j=0; j<N; j++)
                cout << c[i][j] << " ";
    }
    bool bfs(){

        d.clear(),d.resize(N,-1);
        int *q = new int[N+10],K=0,i;

        q[K++]=s; d[s]=0;
        for (i=0; i<K; i++){
            int nod = q[i];

            for (int nxt : g[nod]){
                if (c[nod][nxt]-f[nod][nxt]>0 && d[nxt]==-1){
                    d[nxt]=d[nod]+1;
                    q[K++]=nxt;
                }
            }
        }

        delete[] q;

        return d[t]!=-1;
    }
};
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> N;

    int i,j; ll res,sum=0,sumn=0;
    for (i=1; i<=N; i++){
        cin >> a[i];
        sum+=a[i];
        if (a[i]<0) sumn+=a[i];
    }

    int s=0,f=N+2;
    MaxFlow mf(N+10,s,f);

    for (i=1; i<=N; i++)
        for (j=2*i; j<=N; j+=i)
            mf.add_uedge(i,j,inf);

    for (i=1; i<=N; i++)
        if (a[i]>=0) mf.add_uedge(i,f,a[i]);
        else mf.add_uedge(s,i,-a[i]);

    sumn+=mf.getmaxflow();


    cout << (sum-sumn) << "\n";
	return 0;
}


Measured memory_bytes: 512