#include<bits/stdc++.h>
#define N 105
#define M 100005
#define inf 1000000000
using namespace std;
int i,j,k,l,s,n,m,tot,last[N],S,T,Next[M],to[M],flow[M],q[N],dis[N],a[N];
long long ans;
inline void add(int x,int y,int z) {
	Next[++tot]=last[x]; last[x]=tot; to[tot]=y; flow[tot]=z;
}
inline bool bfs() {
	int l=0,r=1; q[1]=S; 
	for (int i=S;i<=T;i++) dis[i]=inf;
	dis[S]=0;
	while (l<r) {
		int k=q[++l];
		for (int i=last[k];i;i=Next[i]) {
			if (!flow[i]||dis[to[i]]!=inf) continue;
			dis[q[++r]=to[i]]=dis[k]+1;
		}
	}
	return dis[T]!=inf;
}
inline int dfs(int x,int y) {
	if (x==T) return y;
	int sum=0;
	for (int i=last[x];i;i=Next[i]) {
		if (!flow[i]||dis[to[i]]!=dis[x]+1) continue;
		int temp=dfs(to[i],min(y-sum,flow[i]));
		if (temp) {
			sum+=temp;
			flow[i]-=temp;
			flow[i^1]+=temp;
		}
		else dis[to[i]]=inf;
		if (sum==y) return y;
	}
	return sum;
}
inline void dinic() {
	while (bfs()) {
		ans-=dfs(S,inf);
	}
}
int main() {
	scanf("%d",&n);
	for (i=1;i<=n;i++) scanf("%d",&a[i]);
	tot=1;
	S=0,T=n+1;
	for (i=1;i<=n;i++) {
		if (a[i]<0) add(i,T,-a[i]),add(T,i,0);
		else add(S,i,a[i]),add(i,S,0),ans+=a[i];
	}
	for (i=1;i<=n;i++) for (j=2;j*i<=n;j++) add(i,i*j,0),add(i*j,i,inf);
	dinic();
	printf("%lld\n",ans);
}