#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef __int128 ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
#define vc vector
#define db double
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bin(x) (1ll<<(x))
#define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
#define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
#define mem(x,val) memset(x,val,sizeof x)
#define Swap(a,b,n) for(int I=0;I<=n;I++) swap(a[I],b[I])
#define PC __builtin_popcountll
#ifdef DEBUG
	#define debug(A,args...) fprintf(stderr,A,##args)
#else
	#define debug(A,args...) printf("")
#endif
#define deb debug("line %d\n",__LINE__)
namespace mine
{
	ll qread()
	{
		ll ans=0,f=1;char c=getchar();
		while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num){if(num<0) putchar('-'),num=-num;if(num>=10) write(num/10);putchar('0'+num%10);}
	void write1(ll num){write(num);putchar(' ');}
	void write2(ll num){write(num);putchar('\n');}
	template<typename T>inline bool chmax(T&a,const T&b){return a<b?a=b,1:0;}
	template<typename T>inline bool chmin(T&a,const T&b){return a>b?a=b,1:0;}
	ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
	bool IN(ll x,ll l,ll r){return l<=x and x<=r;}
	void GG(){puts("-1");exit(0);}
	
	const db eps=1e-8;
	const int INF=0x3f3f3f3f;
	const int MOD=1e9+7;
	int mm(const int x){return x>=MOD?x-MOD:x;}
	template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
	ll qpower(ll x,ll e,int mod=MOD){ll ans=1;while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
	ll invm(ll x){return qpower(x,MOD-2);}
	const int MM=1e6+10;
	ll fac[MM],facinv[MM],Inv[MM];ll Comb(int n,int m){return n<0 or n<m?0:fac[n]*facinv[m]%MOD*facinv[n-m]%MOD;}
	void PRE()
	{
		fac[0]=1;fo(i,1,MM-1) fac[i]=fac[i-1]*i%MOD;
		facinv[MM-1]=invm(fac[MM-1]);fd(i,MM-1,1) facinv[i-1]=facinv[i]*i%MOD;
		Inv[1]=1;fo(i,2,MM-1) Inv[i]=(MOD-MOD/i)*Inv[MOD%i]%MOD;
	}
	const int N=1e2+10;
	//------------------FIXED------------------
	//�����
	namespace MF
	{
		const int MAX_N=1e2+10,MAX_M=2e3+10;
		int hou[MAX_N],cur[MAX_N];
		struct Edge{int y,g;ll c;}e[MAX_M*2];
		int ln=0;int oth(int x){return x&1?x+1:x-1;}
		void ins(int x,int y,ll c)
		{
			//debug("x=%d y=%d c=%d\n",x,y,c);
			e[++ln]=(Edge){y,hou[x],c};hou[x]=ln;
			e[++ln]=(Edge){x,hou[y],0};hou[y]=ln;
		}
		int st,ed;queue<int> q;int h[MAX_N];
		bool bfs()
		{
			memcpy(cur,hou,sizeof hou);
			memset(h,-1,sizeof h);q.push(st);h[st]=1;
			while(q.size())
			{
				int x=q.front();q.pop();
				for(int k=hou[x];k>0;k=e[k].g)
				{
					int y=e[k].y;
					if(h[y]==-1 and e[k].c) h[y]=h[x]+1,q.push(y);
				}
			}return h[ed]>0;
		}
		ll dfs(int x,ll flow)
		{
			if(x==ed) return flow;
			ll now=0;
			for(int k=cur[x];k>0;)
			{
				int y=e[k].y;
				if(h[y]==h[x]+1 and e[k].c)
				{
					ll t=dfs(y,min(flow-now,e[k].c));
					e[k].c-=t;e[oth(k)].c+=t;now+=t;
				}
				if(e[k].c==0) cur[x]=e[k].g;
				k=e[k].g;if(flow==now) break;
			}
			if(now==0) h[x]=-1;
			return now;
		}
	};

	void main()
	{
		MF::st=0,MF::ed=MF::MAX_N-1;
		int n=qread();ll ans=0,sum=0;fo(i,1,n){ int a=qread();ans+=a;if(a>=0) MF::ins(i,MF::ed,a); else MF::ins(MF::st,i,-a),sum+=(-a); }
		fo(i,1,n) for(int j=i+i;j<=n;j+=i) MF::ins(i,j,bin(50));
		while(MF::bfs()) sum-=MF::dfs(MF::st,bin(60));
		debug("sum=%d\n",sum);
		write(ans+sum);
	}
};//����������
signed main()
{
	#ifdef DEBUG
	//freopen("a.in","r",stdin);
	freopen("z.txt","r",stdin);
	//freopen("a.out","w",stdout);
	#endif
	srand(time(0));
	mine::PRE();
	mine::main();
	debug("\n------------------------------------------\nTime: %.2lf s",1.0*clock()/CLOCKS_PER_SEC);
}

Measured memory_bytes: 23680