#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string.h>
#define MAX_V 300
#define INF 100000000000000
using namespace std;

struct edge {long long to,cap,rev;};

vector<edge> G[MAX_V];
long long level[MAX_V],iter[MAX_V];

void add_edge(int from, int to, long long cap){
		G[from].push_back((edge){to,cap,(long long)G[to].size()});
		G[to].push_back((edge){from,0,(long long)G[from].size()-1});
}

void bfs(int s){
	memset(level,-1,sizeof(level));
	queue<int> que;
	level[s] = 0;
	que.push(s);
	while(!que.empty()){
		int v = que.front();
		que.pop();
		for(int i=0;i<G[v].size();i++){
			edge &e = G[v][i];
			if(e.cap>0 && level[e.to]<0){
				level[e.to] = level[v] + 1;
				que.push(e.to);
			}
		}
	}
}

long long dfs(int v, int t, long long f){
	if(v==t) return f;
	for(int i = iter[v];i<G[v].size();i++){
		edge &e = G[v][i];
		if(e.cap>0 && level[v]<level[e.to]){
		int d = dfs(e.to,t,min(f,e.cap));
			if(d>0){
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}
	
long long max_flow(int s, int t){
	long long flow = 0;
	for(;;){
		bfs(s);
		if(level[t]<0) return flow;
		memset(iter,0,sizeof(iter));
		long long f;
		while((f=dfs(s,t,INF))>0){
			flow += f;
		}
	}
}

int main(){
	int n,s,t;
	long long sum=0,a[110];
	cin >> n;
	s = 0; t = n+1;
	for(int i=1;i<=n;i++){
		cin >> a[i];
		for(int j=1;j<i;j++){
			if(i%j==0){
				add_edge(i,j,INF);
			}
		}
		if(a[i]>0){
			add_edge(s,i,a[i]);
			sum += a[i];
		}else{
			add_edge(i,t,-a[i]);
		}
	}
	
	long long f = max_flow(0,n+1);
	cout << sum - f << endl;
}
		
			