//  Copyright 2020 Nikita Golikov

#include <bits/stdc++.h>

using namespace std;

using i64 = int64_t;
using ui64 = uint64_t;

#ifdef GOLIKOV
mt19937_64 rng(566);
#else
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#endif

template <typename T>
T rnd_helper(T from, T to, true_type) {
  return uniform_int_distribution<T>(from, to)(rng);
}

template <typename T>
T rnd_helper(T from, T to, false_type) {
  return uniform_real_distribution<T>(from, to)(rng);
}

template <typename T>
T rnd(T from, T to) {
  return rnd_helper(from, to, is_integral<T>{});
}

template <typename A, typename B, typename Cmp>
bool set_min(A& x, B const& y, Cmp&& cmp) {
  if (cmp(y, x)) {
    x = y;
    return true;
  }
  return false;
}

template <typename A, typename B>
bool set_min(A& x, B const& y) {
  return set_min(x, y, less<>{});
}

template <typename A, typename B>
bool set_max(A& x, B const& y) {
  return set_min(x, y, greater<>{});
}

struct dinic {
  struct edge {
    int from;
    int to;
    i64 cap;
    i64 flow{};
  };

  int n;
  vector<edge> edges;
  vector<vector<int>> graph;
  vector<int> d;

  dinic(int n_) : n(n_), graph(n) {}

  void add_edge(int from, int to, i64 cap) {
    graph[from].push_back((int) edges.size());
    edges.push_back({from, to, cap});
    graph[to].push_back((int) edges.size());
    edges.push_back({to, from, 0});
  }

  bool bfs() {
    d.assign(n, -1);
    d[0] = 0;
    vector<int> q(n);
    int qt = 1;
    for (int qh = 0; qh < qt; ++qh) {
      int v = q[qh];
      for (auto ei : graph[v]) {
        auto& e = edges[ei];
        if (e.flow < e.cap && !~d[e.to]) {
          d[e.to] = d[v] + 1;
          q[qt++] = e.to;
        }
      }
    }
    return ~d.back();
  }

  i64 max_flow() {
    i64 ans = 0;
    while (bfs()) {
      vector<vector<int>::iterator> ptr(n);
      for (int i = 0; i < n; ++i) ptr[i] = graph[i].begin();
      function<i64(int, i64)> dfs = [&](int v, i64 cMin) -> i64 {
        if (v == n - 1) {
          return cMin;
        }
        for (; ptr[v] != graph[v].end(); ++ptr[v]) {
          auto ei = *ptr[v];
          auto& e = edges[ei];
          if (e.flow < e.cap && d[e.to] == d[v] + 1) {
            auto push = dfs(e.to, min(cMin, e.cap - e.flow));
            if (push) {
              e.flow += push;
              edges[ei ^ 1].flow -= push;
              return push;
            }
          }
        }
        return 0;
      };
      while (auto pushed = dfs(0, (i64) 1e18)) {
        ans += pushed;
      }
    }
    return ans;
  }
};

int main() {
#ifdef GOLIKOV
  freopen("in", "rt", stdin);
  auto _clock_start = chrono::high_resolution_clock::now();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;
  dinic graph(n + 2);
  vector<int> a(n);
  i64 sum_pos = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i] < 0) {
      graph.add_edge(0, i + 1, -a[i]);
    } else {
      graph.add_edge(i + 1, n + 1, a[i]);
      sum_pos += a[i];
    }
  }
  i64 const INF = (i64) 1e12;
  for (int i = 1; i <= n; ++i) {
    for (int j = i + i; j <= n; j += i) {
      graph.add_edge(i, j, INF);
    }
  }
  cout << sum_pos - graph.max_flow() << '\n';

#ifdef GOLIKOV
  cerr << "Executed in " << chrono::duration_cast<chrono::milliseconds>(
          chrono::high_resolution_clock::now() - _clock_start).count() << "ms."
       << endl;
#endif
  return 0;
}


Measured memory_bytes: 256