#include<bits/stdc++.h>
using namespace std;

struct edge{long long t; long long c; long long r;};
vector<edge> G[105];
long long depth[105], n, INF=1e15, ans, a;

void add_edge(long long f, long long t, long long c){
	G[f].push_back(edge{t, c, (long long)G[t].size()});
	G[t].push_back(edge{f, 0, (long long)G[f].size()-1});
}

bool bfs(long long s, long long t){
	memset(depth,-1,sizeof(depth));
	depth[s] = 0;
	queue<long long> que;
	que.push(s);
	while(!que.empty()){
		long long v = que.front(); 
		que.pop();
		for(edge e: G[v]) if(e.c && depth[e.t] == -1){
			depth[e.t] = depth[v] + 1;
			que.push(e.t);
		}
	}
	return depth[t] != -1;
}

long long dfs(long long v, long long t, long long f){
	if(v == t) return f;
	long long ret = 0;
	for(edge& e: G[v]){
		if(depth[v] < depth[e.t] && e.c){
			long long d = dfs(e.t, t, min(f - ret, e.c));
			if(d){
				e.c -= d; G[e.t][e.r].c += d;
				ret += d;
			}
		}
		if(f == ret) break;
	}
	return ret;
}

long long maxflow(long long s, long long t){
	long long ret = 0;
	while(bfs(s,t)) ret += dfs(s, t, INF);
	return ret;
}
 
int main(){
	cin>>n;
	for(long long i=1; i<=n; i++){
		cin>>a;
		if(a < 0) add_edge(i,n+1,-a);
		else{
			ans += a;
			add_edge(0,i,a);
		}
		for(long long j=i*2; j<=n; j+=i) add_edge(j,i,INF);
	}
	cout<<ans-maxflow(0,n+1)<<endl;
}