#include<iostream>
using namespace std;
int n,a[100];
//Ford-Fulkerson O(FE)
#include<algorithm>
#include<utility>
#include<vector>
#include<limits>
template<typename T>
struct MF{
	vector<vector<pair<pair<int,int>,T> > >G;
	vector<int>used;
	MF(int n_=0):G(n_),used(n_,0){}
	void add_edge(int from,int to,T cap)
	{
		G[from].push_back(make_pair(
			make_pair(to,G[to].size()),cap
		));
		G[to].push_back(make_pair(
			make_pair(from,G[from].size()-1),0
		));
	}
	T dfs(int u,int t,T f,int dfstime)
	{
		if(u==t)return f;
		used[u]=dfstime;
		for(pair<pair<int,int>,T>&e:G[u])
		{
			if(used[e.first.first]<dfstime&&e.second>0)
			{
				T d=dfs(e.first.first,t,min(f,e.second),dfstime);
				if(d>0)
				{
					e.second-=d;
					G[e.first.first][e.first.second].second+=d;
					return d;
				}
			}
		}
		return 0;
	}
	T max_flow(int s,int t)
	{
		T ret=0;
		for(int dfstime=1;;dfstime++)
		{
			T f=dfs(s,t,numeric_limits<T>::max(),dfstime);
			if(f>0)ret+=f;
			else break;
		}
		return ret;
	}
};
int main()
{
	cin>>n;
	MF<long>mf(n+2);
	long ans=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		if(a[i]>=0)ans+=a[i],mf.add_edge(i+1,n+1,a[i]);
		else mf.add_edge(0,i+1,-a[i]);
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=i+i;j<=n;j+=i)mf.add_edge(i,j,numeric_limits<long>::max());
	}
	cout<<ans-mf.max_flow(0,n+1)<<endl;
}