#include<cstdio>
#include<cstring>
#include<queue>
#include<cmath>
using namespace std;
#define INF 0x3f3f3f3f3f3f3f3f
#define int long long
const int Ni = 510;
const int MAX = 1ll<<35;
struct Edge{
	int u,v,c;
	int next;
}edge[20*Ni];
int n,m;
int edn,sp,tp;
int p[Ni],d[Ni];

void addedge(int u,int v,int c)
{
	edge[edn].u=u; edge[edn].v=v; edge[edn].c=c;
	edge[edn].next=p[u]; p[u]=edn++;
	edge[edn].u=v; edge[edn].v=u; edge[edn].c=0;
	edge[edn].next=p[v]; p[v]=edn++;
}
int bfs()
{
	queue <int> q;
	memset(d,-1,sizeof(d));
	d[sp]=0;
	q.push(sp);
	while(!q.empty())
	{
		 int cur=q.front();
		 q.pop();
		 for(int i=p[cur];i!=-1;i=edge[i].next)
		 {
		     int u=edge[i].v;
		     if(d[u]==-1 && edge[i].c>0)
		     {
		         d[u]=d[cur]+1;
		         q.push(u);
		     }
		 }
	}
	return d[tp] != -1;
}

int dfs(int a,int b)
{
	int r=0;
	if(a==tp)return b;
	for(int i=p[a];i!=-1 && r<b;i=edge[i].next)
	{
		int u=edge[i].v;
		if(edge[i].c>0 && d[u]==d[a]+1)
		{
			int x=min(edge[i].c,b-r);
			x=dfs(u,x);
			r+=x;
			edge[i].c-=x;
			edge[i^1].c+=x;
		}
	}
	if(!r)d[a]=-2;
	return r;
}

int dinic(int sp,int tp)
{
	int total=0,t;
	while(bfs())
		while(t=dfs(sp,MAX)) total+=t;
	return total;
}

int a[120],sum;
signed main()
{
	memset(p,-1,sizeof(p));
	scanf("%lld",&n);
	for (int i=1;i<=n;i++) {
		scanf("%lld",&a[i]);
		if (a[i]<=0) addedge(0,i,-a[i]);
		else addedge(i,n+1,a[i]),sum+=a[i];
		for (int j=i*2;j<=n;j+=i) addedge(i,j,INF);
	}
	sp=0; tp=n+1;
	printf("%lld\n",sum-dinic(0,n+1));
	return 0;
}