#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}
template<typename T>vector<T> & cset(vector<T> &A,T e=T()){for(auto &I:A){I=e;} return A;}

//BEGIN CUT HERE
template<typename T,bool directed>
struct Dinic{
    struct edge {
        int to;
        T cap;
        int rev;
        edge(){}
        edge(int to,T cap,int rev):to(to),cap(cap),rev(rev){}
    };
    
    vector<vector<edge> > G;
    vector<int> level,iter;
    
    Dinic(){}
    Dinic(int n):G(n),level(n),iter(n){}
    
    int add_edge(int from,int to,T cap){
        G[from].emplace_back(to,cap,G[to].size());
        G[to].emplace_back(from,directed?0:cap,G[from].size()-1);
        return G[to].back().rev;
    }
    
    void bfs(int s){
        fill(level.begin(),level.end(),-1);
        queue<int> que;
        level[s]=0;
        que.emplace(s);
        while(!que.empty()){
            int v=que.front();que.pop();
            for(int i=0;i<(int)G[v].size();i++){
                edge &e=G[v][i];
                if(e.cap>0&&level[e.to]<0){
                    level[e.to]=level[v]+1;
                    que.emplace(e.to);
                }
            }
        }
    }
    
    T dfs(int v,int t,T f){
        if(v==t) return f;
        for(int &i=iter[v];i<(int)G[v].size();i++){
            edge &e=G[v][i];
            if(e.cap>0&&level[v]<level[e.to]){
                T d=dfs(e.to,t,min(f,e.cap));
                if(d==0) continue;
                e.cap-=d;
                G[e.to][e.rev].cap+=d;
                return d;
            }
        }
        return 0;
    }
    
    T flow(int s,int t,T lim){
        T fl=0;
        while(1){
            bfs(s);
            if(level[t]<0||lim==0) break;
            fill(iter.begin(),iter.end(),0);
            
            while(1){
                T f=dfs(s,t,lim);
                if(f==0) break;
                fl+=f;
                lim-=f;
            }
        }
        return fl;
    }
    
    T flow(int s,int t){
        return flow(s,t,numeric_limits<T>::max()/2);
    }
    
    T cut(int s,int t,int x,int a){
        static_assert(directed, "must be directed");
        auto &e=G[x][a];
        int y=e.to;
        T ce=e.cap,cr=G[y][e.rev].cap;
        if(cr==0) return 0;
        e.cap=G[y][e.rev].cap=0;
        T cap=cr-flow(x,y,cr);
        if(x!=s&&cap!=0) flow(x,s,cap);
        if(t!=y&&cap!=0) flow(t,y,cap);
        e.cap=ce+cr;
        return cap;
    }
};
//END CUT HERE

int main(){
    ll n;
    cin>>n;
    vector<ll> A(n);
    cin>>A;
    Dinic<ll,true> F(n+2);
    ll s=0,g=n+1;
    ll ans=0;
    const ll INF=1e15;
    for(int i=1;i<=n;i++){
        ll cost=A[i-1];
        if(cost<0){
            F.add_edge(i,g,abs(cost));
        }
        else{
            ans+=abs(cost);
            F.add_edge(s,i,abs(cost));
        }
        for(ll j=2;i*j<=n;j++){
            F.add_edge(i*j,i,INF);
        }
    }
    cout<<ans-F.flow(s,g)<<endl;
    
    
    return 0;
}


Measured memory_bytes: 256