#include <iostream>
#include <vector>

using namespace std;

int N, a[111];

long long f(vector<int> v, int n, bool b)
{
	auto r = 0ll;
	if (b) {
		for (int i = n; i <= N; i += n)
			v[i] = 1;
	}
	else r += a[n];
	while (v[++n]);
	if (n > N) return r;
	if (n < 33) {
		auto i = f(v, n, false);
		auto j = f(v, n, true);
		return i < j ? j + r : i + r;
	}
	if (n == 33) {
		int a3 = a[33];
		int a6 = v[66] ? 0 : a[66];
		int a9 = v[99] ? 0 : a[99];
		if (a3 <= 0 && a3 + a6 <= 0 && a3 + a9 <= 0 && a3 + a6 + a9 <= 0)
			v[33] = v[66] = v[99] = 1;
		else r += a[n];
		while (v[++n]);
	}
	while (n <= N) {
		int a1 = a[n];
		int a2 = n * 2 > N || v[n * 2] ? 0 : a[n * 2];
		if (a1 <= 0 && a1 + a2 <= 0) {
			v[n] = 1;
			if (n * 2 <= N) v[n * 2] = 1;
		}
		else r += a[n];
		while (v[++n]);
	}
	return r;
}

int main()
{
	cin >> N;
	for (int i = 0; i < N; i++)
		cin >> a[i + 1];
	vector<int> d(102);
	cout << f(d, 0, false) << endl;
	return 0;
}
