#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

template <typename Edge>
typename Edge::Flow augment(vector<vector<Edge>> &g,
                            vector<int> &d, vector<int> &iter,
                            int v, int t, const typename Edge::Flow &f) {
  if (v == t) return f;
  for (int &i = iter[v]; i < (int)g[v].size(); i++) {
    auto &e = g[v][i];
    if (e.cap > 0 && d[v] < d[e.to]) {
      typename Edge::Flow ff = augment(g, d, iter, e.to, t, min(f, e.cap));
      if (ff > 0) {
        e.cap -= ff;
        g[e.to][e.rev].cap += ff;
        return ff;
      }
    }
  }
  return 0;
}

template <typename Edge>
typename Edge::Flow max_flow(vector<vector<Edge>> &g, int s, int t,
                             typename Edge::Flow zero = 0) {
  using Flow = typename Edge::Flow;
  const int V = g.size();
  Flow flow = zero;
  for (;;) {
    vector<int> d(V, -1);
    queue<int> que;
    d[s] = zero;
    que.push(s);
    while(!que.empty()) {
      int v = que.front(); que.pop();
      for (const auto &e: g[v]) {
        if (e.cap <= zero || d[e.to] >= zero) continue;
        d[e.to] = d[v] + 1;
        que.push(e.to);
      }
    }
    if (d[t] < zero) return flow;
    vector<int> iter(V, 0);
    Flow f;
    while ((f = augment(g, d, iter, s, t, int(1e9))) > 0) flow += f;
  }
}

struct Edge {
  using Flow = ll;
  int to, rev;
  Flow cap;
  Edge(int t, Flow f, int r) : to(t), rev(r), cap(f) {}
};

using Graph = vector<vector<Edge>>;

void add_edge(Graph &g, int from, int to, Edge::Flow cap) {
  g[from].emplace_back(to, cap, (int)g[to].size());
  g[to].emplace_back(from, 0, (int)g[from].size() - 1);
}

void solve(ll N, vector<ll> a) {
  Graph g(N + 2);
  const int source = N, sink = N + 1;
  ll sum = 0;
  REP(i,N) {
    if (a[i] > 0) { add_edge(g, source, i, a[i]); sum += a[i]; }
    if (a[i] < 0) { add_edge(g, i, sink, -a[i]); }
  }
  REP(i,N) REP(j,N) {
    int x = i + 1, y = j + 1;
    if (y > x && y % x == 0) {
      add_edge(g, j, i, ll(1e18));
    }
  }
  ll flow = max_flow(g, source, sink);
  cout << sum - flow << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll N;
	scanf("%lld", &N);
	vector<ll> a(N-1+1);
	for (int i = 0 ; i <= N-1 ; i++) {
	  scanf("%lld", &a[i]);
	}
	solve(N, a);
	return 0;
}


Measured memory_bytes: 256