#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <utility>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <queue>
#include <stack>
using namespace std;

#define LL   long long
#define ld   long double
#define pii  pair<int,int>
#define pLL  pair<LL,LL>
#define vint vector<int>
#define vLL  vector<LL>

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define F first
#define S second
#define MP make_pair
#define PB push_back

#define Si(x) scanf("%d",&(x));
#define Sii(x,y) scanf("%d %d",&(x),&(y));
#define Siii(x,y,z) scanf("%d %d %d",&(x),&(y),&(z));
#define SL(x) scanf("%lld",&(x));
#define SLL(x,y) scanf("%lld %lld",&(x),&(y));
#define SLLL(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z));

#define Pi(x) printf("%d\n",(x));
#define Pii(x,y) printf("%d %d\n",(x),(y));
#define Piii(x,y,z) printf("%d %d %d\n",(x),(y),(z));
#define Piiii(x,y,z,w) printf("%d %d %d %d\n",(x),(y),(z),(w));
#define Piiiii(a,b,c,d,e) printf("%d %d %d %d %d\n",(a),(b),(c),(d),(e));
#define Piiiiii(a,b,c,d,e,f) printf("%d %d %d %d %d %d\n",(a),(b),(c),(d),(e),(f));
#define PL(x) printf("%lld\n",(x)*1LL);
#define PLL(x,y) printf("%lld %lld\n",(x)*1LL,(y)*1LL);
#define PLLL(x,y,z) printf("%lld %lld %lld\n",(x)*1LL,(y)*1LL,(z)*1LL);
#define PLLLL(x,y,z,w) printf("%lld %lld %lld %lld\n",(x)*1LL,(y)*1LL,(z)*1LL,(w)*1LL);

#define Pi1(x) printf("%d",  (x));
#define PiL(x) printf("%lld",(x));
#define Pspace putchar(' ');
#define Pendl  puts("");

#define MEM0(x) memset( (x), 0, sizeof( (x) ) )
#define MEM1(x) memset( (x),-1, sizeof( (x) ) )
#define REP1(i,n)  for (int i = 1; (n) >= i ; ++i)
#define REP0(i,n)  for (int i = 0; (n) >  i ; ++i)
#define REP(L,R,k) for (int i = (L); (R) >= i; i+= (k) )

int myRnd(int L,int R) {
    return abs(( (rand()<<15)|rand() ) ) % (R-L+1) + L;
}

struct Dinic_Flow {
	static const int MAX_N = 1e2 + 6;
	static const LL INF = 1e17 +7;
	int n,s,t;
	struct Edge {
		LL to,cap,rev;
	};
	vector<Edge> edg[MAX_N];
	void init(int _n,int _s,int _t) {
		for (int i=0;_n>=i;i++) {
			edg[i].clear();
		}
		n=_n;
		s=_s;
		t=_t;
	}
	void add_edge(int from,int to,LL cap) {
		edg[from].push_back({to,cap,SZ(edg[to])});
		edg[to].push_back({from,0,SZ(edg[from])-1});
	}
	int level[MAX_N],iter[MAX_N];
	void bfs(int s) {
		queue<int> que;
		que.push(s);
		memset(level,-1,sizeof(level));
		level[s] = 0;
		while (!que.empty()) {
			int t=que.front();
			que.pop();
			for (Edge e:edg[t]) {
				if (e.cap > 0 && level[e.to]==-1) {
					level[e.to] = level[t] + 1;
					que.push(e.to);
				}
			}
		}
	}
	LL dfs(int id,LL flow) {
		if (id==t) return flow;
		int ret=0;
		for (int &i=iter[id];SZ(edg[id])>i;i++) {
			Edge &e=edg[id][i];
			if (e.cap > 0 && level[e.to] == level[id] + 1) {
				LL ret=dfs(e.to,min(flow,e.cap));
				if (ret>0) {
					e.cap -= ret;
					edg[e.to][e.rev].cap += ret;
					return ret;
				}
			}
		}
		return 0;
	}
	LL flow() {
		LL ret=0;
		while(true) {
			bfs(s);
			if (level[t] == -1) return ret;
			LL tmp=0;
			memset(iter,0,sizeof(iter));
			while ((tmp=dfs(s,INF)) > 0) {
				ret += tmp;
			}
		}
		return ret;
	}
} solver;

const int N = 106;
const LL INF = 1e15+ 6;

int a[N];

int main () {
    srand(time(NULL));
    int n;
    Si(n);
    LL tot=0;
    REP1(i,n) {
        Si(a[i]);
        if (a[i] > 0 ) tot += a[i];
    }
    int s=0,t=n+1;
    solver.init(t,s,t);
    REP1(i,n) {
        if (a[i] > 0) {
            solver.add_edge(s,i,a[i]);
        }
        else {
            solver.add_edge(i,t,-a[i]);
        }
        REP1(j,n) {
            if (i%j==0) {
                //Pii(i,j);
                //cout<<"edge : ";PLLL(i,j,INF);
                solver.add_edge(i,j,INF);
            }
        }
    }
    //LL ret=solver.flow();
    //PL(ret);
    PL(tot-solver.flow());
}



Measured memory_bytes: 256