#include <bits/stdc++.h>

using namespace std;

using LL = long long;
using PII = pair<int, int>;
using ll = long long;
using DBL = double;
using VI = vector<int>;
using VD = vector<DBL>;
using VVI = vector<VI>;
using VVD = vector<VD>;
#define FOR(i,a,b) for(int i = a; i < b; i++)
#define REP(i,n) FOR(i,0,n)
#define SZ(a) ((int)((a).size()))
#define ALL(x) (x).begin(), (x).end()
#define SET(a,v) memset((a), (v), sizeof(a))
#define EB emplace_back
#define PB push_back
#define MP make_pair
#define ST first
#define ND second

// #define trace(...) {__f(#__VA_ARGS__, __VA_ARGS__);}
// template<typename Arg> void __f(const char* name, Arg&& arg) {
//   cerr << name << " = " << arg << std::endl;
// } template <typename Arg1, typename... Args>
// void __f(const char* names, Arg1&& arg1, Args&&... args) {
//   const char* comma = strchr(names + 1, ',');
//   cerr.write(names, comma - names) << " = " << arg1<<" | ";__f(comma+1, args...); }
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds; // OST: find_by_order, order_of_key
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// #pragma GCC optimize("Ofast")
// optimize("unroll-loops")
// target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// /*** RNGS ***/
// SEED=chrono::steady_clock::now().time_since_epoch().count();
// // or high_resolution_clock
// mt19937 rng(SEED); /*or*/ random_device rd; mt19937 rng(rd());
// uniform_int_distribution<> dis(MIN, MAX);// usage: dis(rng)
// struct chash {int operator()(int x) const {return x^SEED;}};
// gp_hash_table<int,int,chash>m;//use cc if very less updates
// /*** FAST IO ***/
// inline int scan(){ bool y=0; int x=0; char c=getchar_unlocked();
// while(c<'0'||c>'9'){ if(c=='-')y=1; c=getchar_unlocked();}
// while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+c-'0';c=getchar_unlocked();}
// return y?-x:x; }

const int MAXN = 128;
int a[MAXN];

struct Dinic { using FT = long long;
  static const FT INF = 1ll << 60; // CHOOSE CAREFULLY!
  struct Edge { int from, to; FT cap, flow = 0;
    Edge(int from, int to, FT cap) : from(from), to(to), cap(cap) {}
  };
  int n, m = 0, src, dest; FT LIM = 1;
  vector<Edge> edges; vector<VI> adj; VI level, ptr;
  Dinic(int n) : n(n), adj(n), level(n), ptr(n) {}
  void add_edge(int u, int v, FT cap) {
    edges.EB(u, v, cap); adj[u].PB(m); m++;
    edges.EB(v, u, 0);   adj[v].PB(m); m++;
  }
  bool bfs() { fill(ALL(level), -1); level[src] = 0;
    VI q(n+10); int qh = 0, qt = -1; q[++qt] = src;
    while (qh <= qt) { // QUEUE be careful
      int u = q[qh++]; // QUEUE be careful
      for (int id : adj[u]) { int v = edges[id].to;
        if (edges[id].cap - edges[id].flow < LIM) continue;
        if (level[v] != -1) continue;
        level[v] = level[u] + 1;
        q[++qt] = v; // QUEUE be careful
      }
    } return level[dest] != -1;
  }
  FT dfs(int u, FT pushed) {
    if (pushed == 0) return 0;
    if (u == dest) return pushed;
    for (int& cid = ptr[u]; cid < SZ(adj[u]); cid++) {
      int id = adj[u][cid]; int v = edges[id].to;
      if (level[u] + 1 != level[v]) continue;
      FT tr = dfs(v, min(pushed, edges[id].cap - edges[id].flow));
      if (tr > 0) {
        edges[id].flow += tr; edges[id ^ 1].flow -= tr;
        return tr;
    } } return 0;
  }
  FT max_flow(int s, int t) { src = s, dest = t; FT f = 0;
    // for (LIM = INF >> 1; LIM > 0; LIM >>= 1) // SCALING
      while (bfs()) {  fill(ALL(ptr), 0);
        while (FT pushed = dfs(s, INF)) f += pushed;
      }
    return f;
  }
};

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin >> n;
	LL sum = 0;
	for(int i=1; i<=n; ++i) {
		cin >> a[i];
		if(a[i] >= 0) sum += a[i];
	}
	Dinic mf(n+2);
	int s = 0, t = n + 1;
	for(int i=1; i<=n; ++i) {
		for(int j=i+1; j<=n; ++j) {
			if( ( j % i ) ==0) {
				mf.add_edge(i, j, (1<<30));
			}
		}
	}
	for(int i=1; i<=n; ++i) {
		if(a[i] < 0) mf.add_edge(s, i, -a[i]);
		if(a[i] > 0) mf.add_edge(i, t, a[i]);
	}
	cout << sum - mf.max_flow(s, t) << endl;
	return 0;
}

Measured memory_bytes: 256