// #includes {{{
#ifdef HEADER_H
#include "header.hpp"
#else
#include <bits/stdc++.h>
#endif

using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair

#define EXIST(e,s) ((s).find(e)!=(s).end())

#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define debug_v(x) cerr << #x << " = [";REP(__ind,(x).size()){cerr << (x)[__ind] << ", ";}cerr << "] (L" << __LINE__ << ")" << endl;

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)

typedef long long Int;
typedef unsigned long long uInt;
typedef long double rn;

template<class T>
T inf(){
	return numeric_limits<T>::has_infinity?numeric_limits<T>::infinity():(numeric_limits<T>::max()/2);
}

typedef pair<int,int> pii;

/*
#ifdef MYDEBUG
#include"debug.h"
#include"print.h"
#endif
*/
// }}}


//{{{ io
FILE *file_in=stdin,*file_out=stdout;
#define fin normal_in
#define fout normal_out
//const char fname[]="";
//FILE *fin=fopen(fname,"r"),*fout=fopen(fname,"w");
#ifdef __MINGW32__
#define LLD "%I64d"
#define LLU "%I64u"
#else
#define LLD "%lld"
#define LLU "%llu"
#endif
struct NORMAL_IN{
	bool cnt;
	NORMAL_IN():cnt(true){}
	operator int() const {return cnt;}
#define endl "\n"
	NORMAL_IN& operator>>(int &n){cnt=fscanf(file_in,"%d",&n)!=EOF;return *this;}
	NORMAL_IN& operator>>(unsigned int &n){cnt=fscanf(file_in,"%u",&n)!=EOF;return *this;}
	NORMAL_IN& operator>>(long long &n){cnt=fscanf(file_in,LLD,&n)!=EOF;return *this;}
	NORMAL_IN& operator>>(unsigned long long &n){cnt=fscanf(file_in,LLU,&n)!=EOF;return *this;}
	NORMAL_IN& operator>>(double &n){cnt=fscanf(file_in,"%lf",&n)!=EOF;return *this;}
	NORMAL_IN& operator>>(long double &n){cnt=fscanf(file_in,"%Lf",&n)!=EOF;return *this;}
	NORMAL_IN& operator>>(char *c){cnt=fscanf(file_in,"%s",c)!=EOF;return *this;}
	NORMAL_IN& operator>>(string &s){
		s.clear();
		for(bool r=false;;){
			const char c=getchar();
			if(c==EOF){ cnt=false; break;}
			const int t=isspace(c);
			if(!r and !t)r=true;
			if(r){
				if(!t)s.push_back(c);
				else break;
			}
		}
		return *this;
	}
	template<class T>
		NORMAL_IN& operator>>(vector<T> &v){
			int v_size = v.size();
			REP(i,v_size){
				*this>>v[i];
			}
			return *this;
		}
} normal_in;

struct NORMAL_OUT{
	NORMAL_OUT& operator<<(const int &n){fprintf(file_out,"%d",n);return *this;}
	NORMAL_OUT& operator<<(const unsigned int &n){fprintf(file_out,"%u",n);return *this;}
	NORMAL_OUT& operator<<(const long long &n){fprintf(file_out,LLD,n);return *this;}
	NORMAL_OUT& operator<<(const unsigned long long &n){fprintf(file_out,LLU,n);return *this;}
	NORMAL_OUT& operator<<(const double &n){fprintf(file_out,"%lf",n);return *this;}
	NORMAL_OUT& operator<<(const long double &n){fprintf(file_out,"%Lf",n);return *this;}
	NORMAL_OUT& operator<<(const char c[]){fprintf(file_out,"%s",c);return *this;}
	NORMAL_OUT& operator<<(const string &s){fprintf(file_out,"%s",s.c_str());return *this;}
} normal_out;
struct ERR_OUT{
	template<class T>
		ERR_OUT& operator<<(const T &a){
			cerr<<"\x1b[7m"<<a<<"\x1b[m";
			return *this;
		}
} ferr;
//}}}

//{{{ Graph<Weight> g(size); addEdge(g,{src,dst},weight); matrix<Weight> A(n,m);
typedef int Node;
template<class Weight>
struct edge {
	int src, dst;
	Weight weight;
	int rev;
	edge(int src, int dst, Weight weight=1,int rev=-1) :
		src(src), dst(dst), weight(weight), rev(rev){ }
};
template<class Weight>
bool operator < (const edge<Weight> &e, const edge<Weight> &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
		e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
//typedef vector<edge> edges;
//typedef vector<edges> Graph;
 
template<class Weight>
struct matrix:vector<vector<Weight> >{
	matrix(const array<int,2> &a, Weight w=0):vector<vector<Weight> >(a[0],vector<Weight>(a[1],w)){}
	matrix(const array<int,1> &a, Weight w=0):vector<vector<Weight> >(a[0],vector<Weight>(a[0],0)){}
	matrix(){}
};
 
template<class Weight>
struct graph:vector<vector<edge<Weight> > >{
	Weight inf{::inf<Weight>()};
	graph(){}
	graph(const int &n):vector<vector<edge<Weight> > >(n){}
	void _add_edge(int from, int to, Weight w, int rev=-1){
		if((int)this->size() < from + 1)this->resize(from + 1);
		this->at(from).push_back(edge<Weight>(from,to,w,rev));
	}
};
//add bi-directional edge
template<class Weight>
void addBiEdge(graph<Weight> &g, const pair<int,int> &e, Weight w=1){
	const int &from = e.first, &to = e.second;
	g._add_edge(from,to,w,g[to].size());
	g._add_edge(to,from,w,g[from].size()-1);
}
//add directional edge
template<class Weight>
void addEdge(graph<Weight> &g, const pair<int,int> &e, Weight w=1){
	const int &from = e.first, &to = e.second;
	g._add_edge(from,to,w);
}
 
typedef Int Weight;
typedef edge<Weight> Edge;
typedef vector<edge<Weight> > Edges;
typedef graph<Weight> Graph;
typedef matrix<Weight> Matrix;
 
#ifdef DEBUG
#include"graph/graphviz.h"
#endif
//}}}

/*
	MaxFlow mf(Graph g,int s,int t)
	mf.result
*/
//{{{ Dinic max_flow
void addFlowEdge(Graph &g,int src,int dst,Weight cap){
	while(g.size()<max(src,dst)+1)g.push_back(Edges());
	g[src].push_back(Edge(src,dst,cap,g[dst].size()));
	g[dst].push_back(Edge(dst,src,0,g[src].size()-1));
}
void addBiFlowEdge(Graph &g,int src,int dst,Weight cap){
	while(g.size()<max(src,dst)+1)g.push_back(Edges());
	g[src].push_back(Edge(src,dst,cap,g[dst].size()));
	g[dst].push_back(Edge(dst,src,cap,g[src].size()-1));
}

struct MaxFlow{
	static const Weight FLOW_INF=(Weight)20000000000ll;
	const Graph &g;
	vector<vector<Weight> > res;
	const int n;
	vector<int> level,iter;
	Weight result;
	MaxFlow(Graph &g,int s,int t):g(g),n(g.size()){calc(s,t);}
	void bfs(vector<int> &level,int s){
		level.assign(n,-1);
		queue<int> q;
		level[s]=0;
		q.push(s);
		while(not q.empty()){
			int v=q.front();q.pop();
			for(int i=0;i<(int)g[v].size();i++){
				const Edge &e=g[v][i];
				if(res[v][i]>0 and level[e.dst]<0){
					level[e.dst]=level[v]+1;q.push(e.dst);
				}
			}
		}
	}
	Weight dfs(int v, int t, Weight f){
		if(v==t)return f;
		for(int &i=iter[v];i<(int)g[v].size();i++){
			const Edge &e=g[v][i];
			if(res[v][i]>0 and level[v]<level[e.dst]){
				Weight d=dfs(e.dst,t,min(f,res[v][i]));
				if(d>0){
					res[v][i]-=d;
					res[e.dst][e.rev]+=d;
					return d;
				}
			}
		}
		return Weight(0);
	}
	Weight calc(int s,int t){
		res.assign(n,vector<Weight>());
		REP(i,n)REP(j,g[i].size())res[i].push_back(g[i][j].weight);
		result=0;
		for(;;){
			bfs(level,s);
			if(level[t]<0)return result;
			iter.assign(n,0);
			Weight f;
			while((f=dfs(s,t,FLOW_INF))>0)result+=f;
		}
	}
	//additional feature
	bool decreaseable(int v0,int i0){
		if(res[v0][i0]>0)return true;
		vector<bool> vis(n,false);
		decrease_dfs(v0,i0,v0,vis);
		return vis[g[v0][i0].dst];
	}
	void decrease_dfs(int v0,int i0,int v,vector<bool> &vis){
		if(vis[v])return;
		vis[v]=true;
		REP(i,g[v].size()){
			if(res[v][i]==0)continue;
			decrease_dfs(v0,i0,g[v][i].dst,vis);
		}
	}
};
//}}}


Int N;
vector<Int> a;

void solve(){
	int D = N + 2;
	int s = D - 2, t = D - 1;
	Graph G(D);
	Int ans = 0;
	REP(i,N){
		if(a[i]>=0)addFlowEdge(G,i,t,a[i]),ans+=a[i];
		else addFlowEdge(G,s,i,-a[i]);
	}
	REP(i,N){
		for(int j=i+1;j<N;j++){
			if((j+1)%(i+1)==0){
				addFlowEdge(G,i,j,MaxFlow::FLOW_INF);
			}
		}
	}
	MaxFlow mf(G,s,t);
	fout<<ans-mf.result<<endl;
}

//{{{ main function
int main(){	
	
	fin >> N;
	a.assign(N-1+1,Int());
	for(int i = 0 ; i <= N-1 ; i++){
		fin >> a[i];
	}
	solve();
	return 0;
}
//}}}


Measured memory_bytes: 256