#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define FOR(i,a,b) for (int i=(a),for_##i##_max=(b);i<=(for_##i##_max);++i)
#define RFOR(i,a,b) for (int i=(a),rfor_##i##_min=(b);i>=(rfor_##i##_min);--i)
#define REP(i,n) for (int i=0,rep_##i##_len=(n);i<(rep_##i##_len);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

namespace { // Basics

template<typename T>
void chmin(T &x, T y) {
  x = std::min(x, y);
}

template<typename T>
void chmax(T &x, T y) {
  x = std::max(x, y);
}

template<typename T>
__attribute__((unused))
const auto minimum = static_cast<T const &(*)(T const &, T const &)>(std::min);

template<typename T>
__attribute__((unused))
const auto maximum = static_cast<T const &(*)(T const &, T const &)>(std::max);

template<typename T>
__attribute__((unused))
T constexpr infty = std::numeric_limits<T>::max / 3;
template<>
__attribute__((unused))
auto constexpr infty<int> = 1'100'100'100;
template<>
__attribute__((unused))
auto constexpr infty<long long int> = 100'500'400'300'200'100LL;

using lli = long long int;
using ld = long double;

} // namespace

template <typename T>
class dinic {
  public:
    struct edge {
      explicit edge(size_t t, T c, size_t r):
        to(t), cap(c), rev(r) {}
      size_t to; T cap; size_t rev;
    };

    explicit dinic(size_t v): G(v), level(v) {}
    ~dinic() = default;

    void add_edge(size_t from, size_t to, T cap) {
      G[from].emplace_back(to, cap, G[to].size());
      G[to].emplace_back(from, 0, G[from].size() - 1);
    }
    void bfs(size_t s) {
      std::fill(level.begin(), level.end(), -1);
      std::queue<size_t> que;
      level[s] = 0;
      que.push(s);
      while (!que.empty()) {
        const auto v = que.front();
        que.pop();
        for (auto &&e : G[v]) {
          if (e.cap <= 0 || level[e.to] >= 0) continue;
          level[e.to] = level[v] + 1;
          que.push(e.to);
        }
      }
    }
    T dfs(size_t v, size_t t, T f) {
      if (v == t) return f;
      for (auto &&e : G[v]) {
        if (e.cap <= 0 || level[v] >= level[e.to]) continue;
        T d = dfs(e.to, t, std::min(f, e.cap));
        if (d > 0) {
          e.cap -= d;
          reverse(e).cap += d;
          return d;
        }
      }
      return 0;
    }
    T max_flow(size_t s, size_t t) {
      T flow = 0;
      while (true) {
        bfs(s);
        if (level[t] < 0) return flow;
        T f;
        while ((f = dfs(s, t, infty<lli>)) > 0) {
          flow += f;
        }
      }
    }
  private:
    std::vector<std::vector<edge>> G;
    std::vector<T> level;
    edge &reverse(edge const &e) {
      return G[e.to][e.rev];
    }
};

using namespace std;

void solve(int n, vector<lli> const &as) {
  dinic<lli> ff(n+200);
  int destroy = 150, protect = 151;
  lli offset = 0;
  FOR(i, 1, n) {
    if (as[i] > 0) {
      offset += as[i];
      ff.add_edge(protect, i, as[i]);
    } else {
      ff.add_edge(i, destroy, -as[i]);
    }
    for (int j = 2 * i; j <= n; j += i) {
      ff.add_edge(j, i, infty<lli>);
    }
  }
  cout << offset - ff.max_flow(protect, destroy) << endl;
}

int main() {
  // cout << fixed << setprecision(10);

  int N;
  cin >> N;
  vector<lli> as = { 0 };
  REP(i, N) {
    lli a;
    cin >> a;
    as.push_back(a);
  }
  solve(N, as);
  return 0;
}


Measured memory_bytes: 256