#include "bits/stdc++.h"
using namespace std;
void __dump(int x){cerr << x;}
void __dump(long long x){cerr << x;}
void __dump(long double x){cerr << fixed << setprecision(3) << x;}
void __dump(char x){cerr << '\'' << x << '\'';}
void __dump(const string &x){cerr << '"' << x << '"';}
void __dump(const char *x){cerr << '"' << x << '"';}
void __dump(bool x){cerr << (x ? "true" : "false");}
void _dump(){cerr << "\n";}
template <typename T, typename U> void __dump(const pair<T, U> &x){cerr << '{'; __dump(x.first); cerr << ','; __dump(x.second); cerr << '}';}
template <typename T, typename U, typename V> void __dump(const tuple<T, U, V> &x){cerr << '{'; __dump(get<0>(x)); cerr << ',';  __dump(get<1>(x)); cerr << ',';  __dump(get<2>(x)); cerr << '}';}
template <typename T> void __dump(const T& x){int f=0; cerr << '{'; for(auto&i:x) cerr << (f++ ? "," : ""), __dump(i); cerr << "}";}
template <typename T, typename ... U> void _dump(T t, U ... u){__dump(t); if(sizeof...(u)) cerr << ", "; _dump(u...);}
#ifdef ilyes
	#define dump(x ...) cerr  <<  "|dumping| "  <<  # x  <<  "  =  ", _dump(x) 
#else
	#define dump(...) 1998
#endif
//#define int long long
#define FAST ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define size(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define ln '\n'
#define __ ' '
#define LL long long
#define pii pair<int,int>
const int INF = 1e9; const LL INFLL = 1e18L;
const int N = 100;

int n;
int arr[N+3];

template<typename T> struct Dinic {
	struct Edge { int from, to; T cap, flow; };
	vector<vector<int>> adj;
	vector<Edge> e;
	vector<int> level, edgeCount;
	int n, src, sink;
	Dinic(int _n) {
		n = _n+2; src = _n+1; sink = _n+2;
		adj.assign(n+1, vector<int>());
		level.assign(n+1, 0);
		edgeCount.assign(n+1, 0);
		e.clear();
	}
	void addEdge(int a, int b, T cap) {
		adj[a].emplace_back(size(e));
		e.push_back(Edge{ a, b, cap, 0 });
		
		adj[b].emplace_back(size(e));
		e.push_back(Edge{ b, a, 0, 0 });
	}
	bool bfs() {
		fill(all(level), -1);
		queue<int> q;
		q.push(src);
		level[src] = 0;
		while (!q.empty()) {
			int cur = q.front(); q.pop();
			for (int i = 0; i < size(adj[cur]); i++) {
				int curID = adj[cur][i];
				int nxt = e[curID].to;
				if (level[nxt] == -1 && e[curID].flow < e[curID].cap) {
					q.push(nxt);
					level[nxt] = level[cur] + 1;
				}
			}
		}
		return (level[sink] != -1);
	}
	T sendFlow(int cur, T curFlow) {
		if (cur == sink || curFlow == 0) return curFlow;
		for (; edgeCount[cur] < size(adj[cur]); ++edgeCount[cur]) {
				int curID = adj[cur][edgeCount[cur]];
				int nxt = e[curID].to;
				if (level[nxt] == level[cur] + 1) {
					int tmpFlow = sendFlow(nxt, min(curFlow, e[curID].cap - e[curID].flow));
					if (tmpFlow > 0) {
						e[curID].flow += tmpFlow;
						e[curID ^ 1].flow -= tmpFlow;
						return tmpFlow;
					}
				}
		}
		return 0;
	}
	T maxFlow() {
		T f = 0;
		while(bfs()) {
			fill(all(edgeCount), 0);
			while (T tmpFlow=sendFlow(src, INFLL)) f += tmpFlow;
		}
		return f;
	}
};

int main(){ FAST
	cin >> n;
	for(int i=1; i<=n; ++i){
		cin >> arr[i];
	}

	LL posi = 0;
	for(int i=1; i<=n; ++i){
		if(arr[i] > 0) posi += arr[i];
	}

	Dinic<LL> dinic(n);
	for(int i=1; i<=n; ++i){
		if(arr[i] <= 0) dinic.addEdge(dinic.src, i, abs(arr[i]));
		else dinic.addEdge(i, dinic.sink, arr[i]);
	}

	for(int i=1; i<=n; ++i){
		for(int j=i+i; j<=n; j+=i){
			dinic.addEdge(i, j, INFLL);
		}
	}

	cout << posi - dinic.maxFlow() << ln;

}

Measured memory_bytes: 256