#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 ford_fulkerson {
  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 ford_fulkerson(size_t v): G(v), used(v) {}
    ~ford_fulkerson() = 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);
    }
    T dfs(size_t v, size_t t, T f) {
      if (v == t) return f;
      used[v] = true;
      for (auto &&e : G[v]) {
        if (used[e.to] || e.cap <= 0) 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) {
        std::fill(used.begin(), used.end(), 0);
        T f = dfs(s, t, infty<lli>);
        if (f == 0) return flow;
        flow += f;
      }
    }

  private:
    std::vector<std::vector<edge>> G;
    std::vector<bool> used;
    edge &reverse(edge const &e) {
      return G[e.to][e.rev];
    }
};

template <typename T, template <class> class Solver>
class project_selection {
  public:
    explicit project_selection(size_t n): solver(n+2), offset(0), red(n), blue(n+1) {}
    ~project_selection() = default;

    void add_red_benefit(size_t i, T benefit) {
      if (benefit > 0) {
        offset += benefit;
        solver.add_edge(red, i, benefit);
      } else {
        solver.add_edge(i, blue, -benefit);
      }
    }
    void add_red_penalty(size_t i, T penalty) {
      add_red_benefit(i, -penalty);
    }
    void add_split_penalty(size_t r, size_t b, T penalty) {
      solver.add_edge(r, b, penalty);
    }
    T max_benefit() {
      return offset - solver.max_flow(red, blue);
    }
  private:
    Solver<T> solver;
    T offset;
    size_t const red; size_t const blue;
};

using namespace std;

void solve(int n, vector<lli> const &as) {
  project_selection<lli, ford_fulkerson> proj(n+100);
  FOR(i, 1, n) {
    proj.add_red_benefit(i, as[i]);
    for (int j = 2 * i; j <= n; j += i) {
      proj.add_split_penalty(j, i, infty<lli>);
    }
  }
  cout << proj.max_benefit() << 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