#include <map>
#include <set>
#include <unordered_set>
#include <list>
#include <cmath>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <climits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstring>
#include <algorithm>
#include <array>
#include <assert.h>
#include <functional>
#define _USE_MATH_DEFINES
#include <math.h>
#include <complex>
#include <atomic>
#include <thread>

using namespace std;
typedef long long ll;
#define ln '\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define drep(i,n) int i = 0;for(;i<(n);++i)
#define FOR(i,s,e) for(int i=s;i<=(e);++i)
#define DFOR(i,s,e) int i = s;for(;i<=(e);++i)
#define FORR(i,s,e) for(int i=s;i>=(e);--i)
#define DFORR(i,s,e) int i = s;for(;i>=(e);--i)
#define fore(a, x) for(auto& a : x)
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ft first
#define sd second
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(),a.end()
#define Fill(a,b) memset(a,b,sizeof(a))
template<typename T1, typename T2> bool Max(T1& a, T2 b) { return a<b ? a = b, 1 : 0; }
template<typename T1, typename T2> bool Min(T1& a, T2 b) { return a>b ? a = b, 1 : 0; }




template <typename T>
struct MaxFlow {
  //static const int inf = 1e9;
  static const T eps = (T) 1e-9;

  vector<int> last, used, d, q, to, prev;
  vector<T> cap;
  int n, qi, qj;

  // _n: number of vertexes
  // m: number of edges
  void init(int _n, int m = 0) {
    n = _n;
    last.assign(n, -1);
    q.resize(n);
    cap.clear();
    to.clear();
    prev.clear();
    if (m>0) {
      cap.reserve(m * 2);
      to.reserve(m * 2);
      prev.reserve(m * 2);
    }
  }

  // c2: capacity on reverse edge y->x,
  // if edge y->x should never be used(e.g: to source or from sink or for vertex capacity),
  // then set c2 to -1 to speed up algo by removing the reverse edge from the graph
  void add(int x, int y, T c, T c2 = 0) {
    prev.push_back(last[x]);
    last[x] = cap.size();
    cap.push_back(c);
    to.push_back(y);

    prev.push_back(last[y]);
    if (c2 >= 0) last[y] = cap.size();
    else c2 = 0; // make it easier to clear flow
    cap.push_back(c2);
    to.push_back(x);
  }

  bool bfs(int s, int t) {
    d.assign(n, -1);
    qi = qj = 0;
    d[s] = 0;
    q[qj++] = s;
    while (qi < qj) {
      int cur = q[qi++];
      int dis = d[cur] + 1;
      for (int i = last[cur]; i >= 0; i = prev[i]) if (d[to[i]] == -1 && cap[i] > eps) {
        d[to[i]] = dis;
        if (to[i] == t) return 1;
        q[qj++] = to[i];
      }
    }
    return 0;
  }

  T dfs(int v, int t, T maxf) {
    if (v == t) return maxf;
    T f = 0;
    for (int& i = used[v]; i >= 0; i = prev[i]) if (d[to[i]] > d[v] && cap[i] > eps) {
      T ret = dfs(to[i], t, min(maxf - f, cap[i]));
      cap[i] -= ret;
      cap[i ^ 1] += ret;
      if ((f += ret) == maxf) break;
    }
    return f;
  }

  T maxFlow(int s, int t) {
    T ans = 0;
    while (bfs(s, t)) {
      used = last;
      ans += dfs(s, t, numeric_limits<T>::max());
    }
    return ans;
  }

};
MaxFlow<ll> mf;

const int N = 100001, inf = 10000;
int a[N];
int cnt[N];
int n;

void solve() {
  cin >> n;
  FOR(i, 1, n)cin >> a[i];
  int st = 0, fin = n + 1;
  mf.init(fin + 1);
  ll ans = 0;
  ll inf = 1e18;
  FOR(i, 1, n) {
    if (a[i] >= 0) mf.add(i, fin, a[i], -1), ans += a[i];
    else mf.add(st, i, -a[i], -1);
  }
  FOR(i, 1, n) if(a[i]<0) {
    for (int j = i + i; j <= n; j += i) {
      mf.add(i, j, inf);
    }
  }
  ans -= mf.maxFlow(st, fin);
  cout << ans << ln;
  
}



void gen() {
  n = 5;
  //cout << n << ln;
  rep(i, n) {
    int num = rand() % (1000);
    num -= 500;
    //cout << num << ' ';
    a[i + 1] = num;
  }
  //cout << ln;
}

void init() {
  
}

int main(void) {
  ios::sync_with_stdio(false); cin.tie(0); cout.setf(ios::fixed); cout.precision(20);
  //freopen("C:\\Users\\LENOVO\\Documents\\Visual Studio 2015\\Projects\\Test\\Input\\in.in", "r", stdin);

  init();
  int TC = 1;
#if 0
  cin >> TC; cin.get();
#endif
  FOR(TI, 1, TC) {
    //cout << "Case #" << TI << ": ";
    solve();
  }
  
  
  return 0;
}



Measured memory_bytes: 256