#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
const int N=110,M=100010;
int S,T,tt=1;
int head[N],to[M],nxt[M],s[M],v[N],lev[N],a[N];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') ch=getchar(),o=-1;
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
inline bool bfs() {
    memset(lev,0,sizeof(lev));
    int t=0,sum=1;
    v[1]=S,lev[S]=1;
    while(t<sum) {
	int x=v[++t];
	for(int i=head[x];i;i=nxt[i]) {
	    int y=to[i];
	    if(s[i]&&!lev[y]) {
		lev[y]=lev[x]+1,v[++sum]=y;
		if(y==T) return 1;
	    }
	}
    }
    return 0;
}
inline ll dfs(int x,ll Mx) {
    if(x==T) return Mx;
    ll ret=0;
    for(int i=head[x];i;i=nxt[i]) {
	int y=to[i];
	if(s[i]&&lev[y]==lev[x]+1) {
	    int f=dfs(y,min((ll)s[i],Mx-ret));
	    s[i]-=f,s[i^1]+=f;
	    ret+=f;
	    if(ret==Mx) break;
	}
    }
    if(!ret) lev[x]=0;
    return ret;
}
inline void lnk(int x,int y,int z) {
    to[++tt]=y,nxt[tt]=head[x],s[tt]=z,head[x]=tt;
    to[++tt]=x,nxt[tt]=head[y],head[y]=tt;
}
int main() {
    int n;
    ll ans=0;
    cin>>n;
    S=0,T=n+1;
    for(int i=1;i<=n;i++) {
	a[i]=gi();
	if(a[i]>0) lnk(i,T,a[i]),ans+=a[i];
	else lnk(S,i,-a[i]);
	for(int j=i+i;j<=n;j+=i) lnk(i,j,1e9);
    }
    while(bfs())
	ans-=dfs(S,1LL<<60);
    cout<<ans;
    return 0;
}