/*
PROG: arc085e
LANG: C++
    _____
  .'     '.
 /  0   0  \
|     ^     |
|  \     /  |
 \  '---'  /
  '._____.'
 */
#include <bits/stdc++.h>

using namespace std;

long long readi()
{
	long long input = 0;
	char c = ' ';
	while (c < '-')
	{
		c = getchar();
	}
	bool negative = false;
	if (c == '-')
	{
		negative = true;
		c = getchar();
	}
	while (c >= '0')
	{
		input = 10 * input + (c - '0');
		c = getchar();
	}
	if (negative)
	{
		input = -input;
	}
	return input;
}
void printi(long long output)
{
	if (output == 0)
	{
		putchar('0');
		return;
	}
	if (output < 0)
	{
		putchar('-');
		output = -output;
	}
	int aout[20];
	int ilen = 0;
	while(output)
	{
		aout[ilen] = ((output % 10));
		output /= 10;
		ilen++;
	}
	for (int i = ilen - 1; i >= 0; i--)
	{
		putchar(aout[i] + '0');
	}
	return;
}
string reads()
{
	string input = "";
	char c = ' ';
	while (c <= ' ')
	{
		c = getchar();
	}
	while (c > ' ')
	{
		input += c;
		c = getchar();
	}
	return input;
}
void prints(string output)
{
	for (int i = 0; i < output.length(); i++)
	{		
		putchar(output[i]);
	}
	return;
}
int sgn(long long x)
{
	if (x < 0) 
	{
		return -1;
	}
	if (x > 0) 
	{
		return 1;
	}
	return 0;
}

#define MP make_pair
#define PB push_back
#define PF push_front
#define MT make_tuple
#define LB lower_bound
#define UB upper_bound

#define SINF 10007
#define MOD 1000000007
#define INF 1000000861
#define LLINF 1000000000000000861ll
#define CO 1000861
#define EPS 0.000000000000001
#define PI 3.141592653589793
#define MAXN 110
#define MAXM 10010
#define next next_

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int N, M, S, T, E = 2;
int level[MAXN];
ll from[2 * MAXM], to[2 * MAXM], cap[2 * MAXM], next[2 * MAXM], head[2 * MAXM];
ll res;
ll arr[MAXN];
ll ans;

void addedge(int u, int v, ll sz)
{
	from[E] = u;
	to[E] = v;
	cap[E] = sz;
	next[E] = head[u];
	head[u] = E;
	E++;
	from[E] = v;
	to[E] = u;
	cap[E] = 0;
	next[E] = head[v];
	head[v] = E;
	E++;
}
bool bfs()
{
	for (int i = 0; i <= N + 1; i++)
	{
		level[i] = -1;
	}
	queue<int> q;
	q.push(S);
	level[S] = 0;
	while(!q.empty())
	{
		int u = q.front();
		q.pop();
		for (int i = head[u]; i > 0; i = next[i])
		{
			int v = to[i];
			if (cap[i] > 0 && level[v] == -1)
			{
				level[v] = level[u] + 1;
				q.push(v);
				if (v == T)
				{
					return true;
				}
			}
		}
	}
	return false;
}
ll aug(int u, ll flo)
{
	if (u == T)
	{
		res += flo;
		return flo;
	}
	ll rem = flo, gain = 0;
	for (int i = head[u]; i > 0 && rem > 0; i = next[i])
	{
		int v = to[i];
		if (cap[i] > 0 && level[v] == level[u] + 1)
		{
			gain = aug(v, min(rem, cap[i]));
			cap[i] -= gain;
			cap[i ^ 1] += gain;
			rem -= gain;
		}
	}
	return flo - rem;
}
ll dinic()
{
	res = 0ll;
	while(bfs())
	{
		aug(S, LLINF);
	}
	return res;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	srand(time(NULL));
	//	cout << fixed << setprecision(10);	
	//	cerr << fixed << setprecision(10);
	//	if (fopen("arc085e.in", "r"))
	//	{	
	//		freopen ("arc085e.in", "r", stdin);
	//		freopen ("arc085e.out", "w", stdout);
	//	}
	cin >> N;
	for (int i = 1; i <= N; i++)
	{
		cin >> arr[i];
	}
	S = 0; T = N + 1;
	for (int i = 1; i <= N; i++)
	{
		for (int j = i; j <= N; j += i)
		{
			addedge(i, j, LLINF);
		}
		if (arr[i] < 0)
		addedge(0, i, -arr[i]);
		else
		addedge(i, N + 1, arr[i]);
	}
	for (int i = 1; i <= N; i++)
	{
		ans += max(arr[i], 0ll);
	}
	ans -= dinic();
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 384