#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
using namespace std;
using Int = long long;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<55)+1e9; // ~ 3.6 * 1e16
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
using T = tuple<Int,Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
ostream& operator<<(ostream& o,T t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){Int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){Int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}

class Dinic{
public:
  
  struct edge{
    Int to,cap,rev;
    edge(){};
    edge(Int to,Int cap,Int rev):to(to),cap(cap),rev(rev){};
  };

  Int V;
  vector<vector<edge> > G; //グラフの隣接リスト表現
  vector<Int> level;       //sからの距離
  vector<Int> iter;        //どこまで調べ終わったか
  Int INF;
  
  Dinic():V(-1){};
  Dinic(Int V,Int INF=1e9):V(V),G(V),level(V),iter(V),INF(INF){}

  //fromからtoへ向かう容量capの辺をグラフに追加。
  void add_edge(Int from,Int to,Int cap){
    assert(from < V && to < V);
    G[from].push_back(edge(to,cap,G[to].size()));
    G[to].push_back(edge(from,0,G[from].size()-1));
  }

  //sからの最短距離をBFSで計算する
  void bfs(Int s){
    level.clear(); level.resize(V,-1);
    queue<Int> que;
    level[s] = 0;
    que.push(s);
    while(!que.empty()){
      Int v = que.front(); que.pop();
      for(edge &e : G[v])
        if(e.cap > 0 && level[e.to] < 0){
          level[e.to] = level[v] + 1;
          que.push(e.to);
        }
    }
  }

  //増加パスをDFSで探す。
  Int dfs(Int v,Int t,Int 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]){
        Int d = dfs(e.to, t, min(f, e.cap));
        if(d > 0){
          e.cap -= d;
          G[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }

  //sからtへの最大流を求める
  Int max_flow(Int s,Int t){
    assert(V >= 0);
    Int flow=0;
    for(;;){
      bfs(s);
      if(level[t] < 0) return flow;
      iter.clear();iter.resize(V,0);
      Int f;
      while((f=dfs(s ,t ,INF)) > 0 ) flow += f;
    }
  }
};


signed main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);
  
  Int n;
  cin>>n;

  vector<Int> A(n);
  cin>>A;


  Dinic D(n + 10);
  const Int S = D.V - 1, T = S - 1;
  
  for(Int i=1;i<=n;i++)
    for(Int j=2;i*j <= n; j++) {
      D.add_edge(i*j, i , INF);
    }
  
  for(Int i=1;i<=n;i++){
    if(A[i-1] < 0) continue;
    D.add_edge(S, i, abs(A[i-1]));
  }

  for(Int i=1;i<=n;i++){
    if(A[i-1] > 0) continue;
    D.add_edge(i, T, abs(A[i-1]));
  }
    
  Int sum = 0;
  for(Int i=0;i<n;i++) if(A[i] > 0) sum += A[i];
  Int ans = sum - D.max_flow(S, T);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256