#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring>
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//2-dim:vector<vector<Type>> vv(n, vector<Type>(m, d));
//3-dim:vector<vector<vector<Type>>> vvv(n, vector<vector<Type>>(m, vector<Type>(l, d)));
template<typename T>
struct Flow{
private:
    int _n;
    struct _edge {
        int to, rev;
        T cap;
    };
    vector<pair<int, int>> pos;
    vector<vector<_edge>> G;
public:
    Flow():_n(0){}
    Flow(int n):_n(n),G(n){}
    
    void add_edge(int from,int to, T cap){
        pos.push_back({from,G[from].size()});
        G[from].push_back({to,(int)G[to].size(),cap});
        G[to].push_back({from,(int)G[from].size()-1,0});
    }
    struct Edge{
        int from,to;
        T cap,flow;
    };
    Edge get_edge(int x){
        auto _e = G[pos[x].first][pos[x].second];
        auto _re = G[_e.to][_e.rev];
        /* from,to,cap */
        return Edge{pos[x].first, _e.to, _e.cap + _re.cap, _re.cap};
    }
    T maxflow(int s,int t, T lim){
        vector<int> level(_n),iter(_n);
        /* 流す　*/
        auto bfs=[&](){
            queue<int> que;
            fill(level.begin(),level.end(),-1);
            level[s]=0; que.push(s);
            while(!que.empty()){
                int v=que.front(); que.pop();
                for(auto e:G[v]){
                    if(e.cap==0||level[e.to]>=0) continue;
                    level[e.to]=level[v]+1;
                    if(e.to==t) return;
                    que.push(e.to);
                }
            }
        };
        /* 増加パス探索　*/
        auto dfs=[&](auto self,int v, T nf){
            if(v==s) return nf;
            T res=0;
            int lv=level[v];
            for(int& i=iter[v];i<(int)G[v].size();i++){
                _edge& e=G[v][i];
                if(lv<=level[e.to]||G[e.to][e.rev].cap==0)continue;
                T d = self(self,e.to,min(nf-res,G[e.to][e.rev].cap));
                if(d<=0) continue;
                G[v][i].cap+=d;
                G[e.to][e.rev].cap-=d;
                res+=d;
                if(res==nf) break;
            }
            return res;
        };
        T flow=0;
        while(flow<lim){
            bfs();
            if(level[t]==-1) break;
            fill(iter.begin(),iter.end(),0);
            while(flow<lim){
                T f=dfs(dfs,t,lim-flow);
                if(!f) break;
                flow+=f;
            }
        }
        return flow;
    }
    T maxflow(int s,int t){ return maxflow(s,t,numeric_limits<T>::max()); }
};

signed main(){
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    int n; cin >> n;
    Flow<ll> fl(n+2);
    ll ans=0;
    rep(i,n){
        ll a; cin >> a;
        if(a>0){
            ans+=a;
            fl.add_edge(0,i+1,0);
            fl.add_edge(i+1,n+1,a);
        }else{
            fl.add_edge(0,i+1,-a);
            fl.add_edge(i+1,n+1,0);
        }
    }
    const ll INF = 1e15;
    rep(i,n){
        rep(j,n){
            if(i<j&&(j+1)%(i+1)==0){
                fl.add_edge(i+1,j+1,INF);
            }
        }
    }
    ll res=fl.maxflow(0, n+1);
    ans-=res;
    cout << ans << endl;
}




Measured memory_bytes: 3584