#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

//#define INF (1e10)
#define MOD (1000000007)

#define prll2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void prll(const T& x) { cout << setprecision(16) << x << endl; }
template<class T, class... A> void prll(const T& first, const A& ... rest) { cout << first << " "; prll(rest...); }
struct PreMain { PreMain() { cin.tie(0); ios::sync_with_stdio(false); } } premain;


#define N_MAX	(100)


typedef ll FLOW;                // フローを表す型、今回は ll 型
typedef ll COST;                // コストを表す型、今回は ll 型
const ll MAX_V = N_MAX*2 + 2;   // グラフの最大ノード数
const COST INF = 100000000;      // 十分大きい値

// グラフの辺の構造体
struct Edge {
	ll rev, from, to;
	FLOW cap, icap;
	COST cost;
	Edge(ll r, ll f, ll t, FLOW ca, COST co) : rev(r), from(f), to(t), cap(ca), icap(ca), cost(co) {}
};

// グラフ構造体
struct Graph {
	ll V;
	vector<Edge> list[MAX_V];

	Graph(ll n = 0) : V(n) { for (ll i = 0; i < MAX_V; ++i) list[i].clear(); }
	void init(ll n = 0) { V = n; for (ll i = 0; i < MAX_V; ++i) list[i].clear(); }
	void resize(ll n = 0) { V = n; }
	void reset() { for (ll i = 0; i < V; ++i) for (ll j = 0; j < list[i].size(); ++j) list[i][j].cap = list[i][j].icap; }
	inline vector<Edge>& operator [] (ll i) { return list[i]; }

	Edge& redge(Edge& e) {
		if (e.from != e.to) return list[e.to][e.rev];
		else return list[e.to][e.rev + 1];
	}

	void addedge(ll from, ll to, FLOW cap, COST cost) {
		list[from].push_back(Edge((ll)list[to].size(), from, to, cap, cost));
		list[to].push_back(Edge((ll)list[from].size() - 1, to, from, 0, -cost));
	}
};

// 最小費用流を求める関数
COST MinCostFlow(Graph& G, ll s, ll t, FLOW inif) {
	COST dist[MAX_V];
	ll prevv[MAX_V] = { 0 };
	ll preve[MAX_V] = { 0 };

	COST res = 0;
	FLOW f = inif;
	while (f > 0) {
		fill(dist, dist + G.V, INF);
		dist[s] = 0;
		while (true) {
			bool update = false;
			for (ll v = 0; v < G.V; ++v) {
				if (dist[v] == INF) continue;
				for (ll i = 0; i < G[v].size(); ++i) {
					Edge& e = G[v][i];
					if (e.cap > 0 && dist[e.to] > dist[v] + e.cost) {
						dist[e.to] = dist[v] + e.cost;
						prevv[e.to] = v;
						preve[e.to] = i;
						update = true;
					}
				}
			}
			if (!update) break;
		}

		if (dist[t] == INF) return 0;

		FLOW d = f;
		for (ll v = t; v != s; v = prevv[v]) {
			d = min(d, G[prevv[v]][preve[v]].cap);
		}
		f -= d;
		res += dist[t] * d;
		for (ll v = t; v != s; v = prevv[v]) {
			Edge& e = G[prevv[v]][preve[v]];
			Edge& re = G.redge(e);
			e.cap -= d;
			re.cap += d;
		}
	}
	return res;
}


//最大流
bool used[N_MAX * N_MAX * 2 + 10];
ll dfs(Graph& G, ll v, ll t, ll f) {
	if (v == t) return f;
	used[v] = true;
	for (ll i = 0; i < G[v].size(); i++) {
		auto& e = G[v][i];
		if (!used[e.to] && (0 < e.cap)) {
			ll d = dfs(G, e.to, t, min(f, e.cap));
			if (0 < d) {
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

ll maxFlow(Graph& G, ll s, ll t) {
	ll flow = 0;
	for (;;) {
		memset(used, 0, sizeof(used));
		ll f = dfs(G, s, t, numeric_limits<ll>::max());
		if (f == 0) return flow;
		flow += f;
	}
}


int main() {
	ll N;
	cin >> N;
	
	ll A[N_MAX];
	REP(i, N) {
		cin >> A[i];
	}

	ll node_start = (2 * N), node_end = (2 * N + 1);
	Graph G(2 * N + 2);
	REP(i, N) {
		if (A[i] <= 0) {
			G.addedge(node_start, i, -A[i], 0);
		}
		else {
			G.addedge(i, node_end, A[i], 0);
		}
	}

	ll inf = numeric_limits<ll>::max();
	REP(i, N) {
		REP(j, N) {
			ll mul = ((i + 1) * (j + 1));
			if (N < mul) {
				continue;
			}

			G.addedge(i, (mul - 1), inf, 0);
		}
	}

	//auto minCost = MinCostFlow(G, node_start, node_end, N);
	//prll(minCost); 
	auto ans = -maxFlow(G, node_start, node_end);

	REP(i, N) {
		if (0 < A[i]) {
			ans += A[i];
		}
	}
	prll(ans);

	return 0;
}


Measured memory_bytes: 384