#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_genius = 0; ngtkana_is_genius < int(n); ngtkana_is_genius++)
#define rep(i, begin, end) for(int i = int(begin); i < int(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
#define lint long long
auto cmn = [](auto& a, auto b){if (a > b) {a = b; return true;} return false;};
auto cmx = [](auto& a, auto b){if (a < b) {a = b; return true;} return false;};
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail){
  std::cerr << " " << head;
  debug_impl(tail...);
}
#ifndef STOPIT
#define debug(...)\
  std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
  debug_impl(__VA_ARGS__);\
  std::cerr << std::noboolalpha;
#else
#define debug 0;
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

template <typename Flow>
struct residue_edge {
  int to; Flow cap, original_cap; int rev;
  residue_edge(int to, Flow cap, int rev):
    to(to), cap(cap), original_cap(cap), rev(rev){}
};

template <typename Flow>
std::ostream& operator<< (std::ostream& os, const residue_edge<Flow>& e){
  return os
    << "residue_edge{"
    << "to:" << e.to << ","
    << "cap:" << e.cap << ","
    << "rev:" << e.rev
    << "}";
}

template <typename Flow>
struct flow_edge {
  int to; Flow flow;
  flow_edge(int to, Flow flow) : to(to), flow(flow){}
};

template <typename Flow>
std::ostream& operator<< (std::ostream& os, const flow_edge<Flow>& e) {
  return os
    << "flow_edge{"
    << "to:" << e.to << ","
    << "flow:" << e.flow
    << "}";
}

template <typename Flow>
class dinic {
    int                                          n, source, sink;
    std::vector<bool>                            ckd;
    std::vector<int>                             level;
    std::vector<std::vector<residue_edge<Flow>>> graph;

    static constexpr Flow inf_flow = std::numeric_limits<Flow>::max();

    void bfs () {
      std::queue<int> que;
      que.emplace(source); level.at(source) = 0;
      while (!que.empty()) {
        auto crr = que.front(); que.pop();
        for (auto const& e : graph.at(crr)) {
          if (e.cap == 0) continue;
          int nxt = e.to;
          if (level.at(nxt) != -1) continue;
          que.push(nxt);
          level.at(nxt) = level.at(crr) + 1;
        }
      }
    }

    auto dfs (int crr, Flow f = inf_flow) {
      if (crr == sink) return f;
      ckd.at(crr) = true;
      for (auto& e : graph.at(crr)) {
        auto nxt = e.to;
        if (ckd.at(nxt) || e.cap == 0 || level.at(crr) >= level.at(nxt)) continue;
        auto d = dfs(nxt, std::min(f, e.cap));
        if (d > 0) {
          e.cap -= d;
          graph.at(nxt).at(e.rev).cap += d;
          return d;
        }
      }
      level.at(crr) = -1;
      return Flow(0);
    }

  public:
    dinic (int n, int source, int sink):
      n(n), source(source), sink(sink), graph(n){}

    void insert(int u, int v, Flow c) {
      graph.at(u).emplace_back(v, c, graph.at(v).size());
      graph.at(v).emplace_back(u, 0, graph.at(u).size() - 1);
    }

    auto build() {
      Flow ret = 0;
      while (true) {
        level.assign(n, -1);
        bfs();
        if (level.at(sink) == -1) return ret;
        ckd.assign(n, false);
        while (true) {
          auto f = dfs(source);
          if (f == 0) break;
          ret += f;
        }
      }
    }

    auto collect() const {
      std::vector<std::vector<flow_edge<Flow>>> ret(n);
      for (auto i = 0; i < n; i++) {
        for (auto const& e : graph.at(i)) {
          auto flow = e.original_cap - e.cap;
          if (flow > 0) ret.at(i).emplace_back(e.to, flow);
        }
      }
      return ret;
    }
};

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  constexpr long long linf = 1LL << 60;
  int n; std::cin >> n;
  auto s = 0, t = n + 1;
  auto dnc = dinic< lint > (n + 2, s, t);
  lint sum = 0;
  rep(i, 1, n + 1) {
    lint x; std::cin >> x;
    if (x < 0) {
      dnc.insert(s, i, -x);
    } else {
      sum += x;
      dnc.insert(i, t, x);
    }
  }
  rep(d, 1, n + 1) {
    for (auto i = 2 * d; i <= n; i += d) {
      dnc.insert(d, i, linf);
    }
  }
  auto flow = dnc.build();
  auto ret  = sum - flow;
  std::cout << ret << std::endl;
  return 0;
}


Measured memory_bytes: 256