#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;



template <typename T, T INF> class Dinic{
private:
  vector<vector<pair<int,T>>> graph;
  int size, s, t;
  vector<vector<T>> cap;
  vector<int> level;
  
  bool buildLevel(){
    fill(ALL(level), 0);
    level[s] = 1;
    deque<int> deq = {s};
    while(!deq.empty()){
      int cur = deq.front(); deq.pop_front();
      REP(i,size)
        if(level[i]==0 && cap[cur][i]>0){
          level[i] = level[cur] + 1;
          deq.push_back(i);
        }
    }
    return level[t] != 0;
  }
  void dfs(vector<int> &path, T &flow){
    if(path.empty()) return;
    int cur = path.back();
    if(cur == t){
      T f = INF;
      FOR(i,1,(int)path.size()) f = min(f, cap[path[i-1]][path[i]]);
      FOR(i,1,(int)path.size()){
        cap[path[i-1]][path[i]] -= f;
        cap[path[i]][path[i-1]] += f;
      }
      flow += f;
    }else{
      REP(i,size){
        if(cap[cur][i]>0 && level[i]>level[cur]){
          path.push_back(i);
          dfs(path, flow);
          path.pop_back();
        }
      }
    }
  }
  T augment(){
    T f = 0;
    vector<int> path = {s};
    dfs(path, f);
    return f;
  }
  T loop(){
    T f = 0;
    while(buildLevel()) f += augment();
    return f;
  }
 
public:
  Dinic(vector<vector<pair<int,T>>> &_graph): graph(_graph), size(graph.size()) {}
  Dinic(int size): graph(size), size(size){}
  Dinic(){}
 
  void add_edge(int from, int to, const T &cap){
    graph[from].push_back({to, cap});
  }
  
  T max_flow(int _s, int _t){
    cap = vector<vector<T>>(size, vector<T>(size, 0));
    level = vector<int>(size, 0);
 
    REP(i,size)
      for(auto &p : graph[i]){
        int j = p.first;
        T d = p.second;
        cap[i][j] += d;
      }
 
    s = _s;
    t = _t;
 
    return loop();
  }
};






template <typename T, T INF>
class ProjectSelectionProblem{
  int N;
  Dinic<T, INF> flow;

  int s, t;

  T default_gain;

public:
  ProjectSelectionProblem(int N): N(N), flow(N+2), s(N), t(N+1), default_gain(0){
    
  }

  void penalty_if_red(int i, T c){
    assert(c >= 0);
    flow.add_edge(i, t, c);
  }

  void gain_if_red(int i, T c){
    assert(c >= 0);
    default_gain += c;
    penalty_if_blue(i, c);
  }
  
  void penalty_if_blue(int i, T c){
    assert(c >= 0);
    flow.add_edge(s, i, c);
  }

  void gain_if_blue(int i, T c){
    assert(c >= 0);
    default_gain += c;
    penalty_if_red(i, c);
  }

  void penalty_if_red_blue(int i, int j, T c){
    assert(c >= 0);
    flow.add_edge(i, j, c);
  }

  void penalty_if_different(int i, int j, T c){
    assert(c >= 0);
    flow.add_edge(i, j, c);
    flow.add_edge(j, i, c);
  }

  void must_be_red(int i){
    penalty_if_blue(i, INF);
  }

  void mush_be_blue(int i){
    penalty_if_red(i, INF);
  }

  void if_red_then_must_be_red(int i, int j){
    penalty_if_red_blue(i, j, INF);
  }
  

  T run(){
    return default_gain - flow.max_flow(s, t);
  }
};



const LLI inf = 1LL << 50;


int main(){

  int N;
  while(cin >> N){
    vector<LLI> a(N); cin >> a;

    ProjectSelectionProblem<LLI,inf> psp(N);
    
    REP(i,N){
      if(a[i] >= 0){
        psp.gain_if_blue(i, a[i]);
      }else{
        psp.penalty_if_blue(i, -a[i]);
      }
    }

    FORE(i,1,N){
      FORE(j,i+1,N){
        if(j % i == 0){
          psp.if_red_then_must_be_red(i-1, j-1);
        }
      }
    }

    auto ans = psp.run();
    
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 384