#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
const double PI = acos(-1);
const ll MOD = 1e9+7;
const ll MAXN = 2 * 1e3;

vi jalan[MAXN];
ll cap[MAXN][MAXN], val[MAXN], par[MAXN];
ll s, t, f, n, m;
ll res[MAXN][MAXN];

bool bfs(ll skrg) {
	bool vis[MAXN];
	memset(vis, 0, sizeof(vis));

	queue<ll> q;
	q.push(skrg);
	vis[skrg] = 1;
	par[skrg] = -1;

	while (!q.empty()) {
		ll cur = q.front();
		q.pop();

		for (ll i = 0; i < jalan[cur].size(); i++) {
			ll ttg = jalan[cur][i];
			if (!vis[ttg] && res[cur][ttg] > 0) {
				q.push(ttg);
				par[ttg] = cur;
				vis[ttg] = 1;
			}
		}
	}

	return vis[t];
}

int main(){
	cin >> n;
	s = 0; t = n + 1;
	ll tot = 0;
	for (ll i = 1; i <= n; i++) {
		ll x;
		cin >> x;

		if (x > 0) {
			jalan[i].pb(t);
			jalan[t].pb(i);
			cap[i][t] = x;
			tot += x;
		}
		else {
			jalan[s].pb(i);
			jalan[i].pb(s);
			cap[s][i] = -1 * x;

		}
	}

	for (ll i = 1; i <= n; i++) {
		for (ll j = 2*i; j <= n; j+=i) {
			jalan[i].pb(j);
			jalan[j].pb(i);
			cap[i][j] = INT_MAX;
		}
	}	


	for (ll i = 0; i <= n + 1; i++) {
		for (ll j = 0; j <= n + 1; j++) {
			res[i][j] = cap[i][j];
		}
	}
	
	ll mf = 0;

	while (bfs(s)) {
		ll p = INT_MAX;
		for (ll i = t; i != s; i = par[i]) {
			ll j = par[i];
			p = min(p, res[j][i]);
		}
		for (ll i = t; i != s; i = par[i]) {
			ll j = par[i];
			res[j][i] -= p;
			res[i][j] += p;
		}

		mf += p;
	}

	cout << tot - mf << endl;

}