#define STOPIT
#include <bits/stdc++.h>
#define loop(n) for (lint ngtkana_is_a_genius = 0; ngtkana_is_a_genius < lint(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (lint i = lint(begin); (i) < lint(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
#define debug(...)\
	do {\
		std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
		debug_impl(__VA_ARGS__);\
		std::cerr << std::noboolalpha;\
	} while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
	{ for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
	for (auto it = v.begin(); it != v.end(); it++)
		{os << (it != v.begin() ? "," : "") << *it;}
	return os << "}";
}

template <typename Flow>
struct residue_edge {
	int to; Flow cap, original_cap; int rev;
	residue_edge(int to, Flow cap, int rev):
		to(to), cap(cap), original_cap(cap), rev(rev){}
};

template <typename Flow>
std::ostream& operator<< (std::ostream& os, const residue_edge<Flow>& e){
	return os
		<< "residue_edge{"
		<< "to:" << e.to << ","
		<< "cap:" << e.cap << ","
		<< "rev:" << e.rev
		<< "}";
}

template <typename Flow>
struct flow_edge {
	int to; Flow flow;
	flow_edge(int to, Flow flow) : to(to), flow(flow){}
};

template <typename Flow>
std::ostream& operator<< (std::ostream& os, const flow_edge<Flow>& e) {
	return os
		<< "flow_edge{"
		<< "to:" << e.to << ","
		<< "flow:" << e.flow
		<< "}";
}

template <typename Flow>
class dinic {
		int                                          n, source, sink;
		std::vector<bool>                            ckd;
		std::vector<int>                             level;
		std::vector<std::vector<residue_edge<Flow>>> graph;

		static constexpr Flow inf_flow = std::numeric_limits<Flow>::max();

		void bfs () {
			std::queue<int> que;
			que.emplace(source); level.at(source) = 0;
			while (!que.empty()) {
				auto crr = que.front(); que.pop();
				for (auto const& e : graph.at(crr)) {
					if (e.cap == 0) continue;
					int nxt = e.to;
					if (level.at(nxt) != -1) continue;
					que.push(nxt);
					level.at(nxt) = level.at(crr) + 1;
				}
			}
		}

		auto dfs (int crr, Flow f = inf_flow) {
			if (crr == sink) return f;
			ckd.at(crr) = true;
			for (auto& e : graph.at(crr)) {
				auto nxt = e.to;
				if (ckd.at(nxt) || e.cap == 0 || level.at(crr) >= level.at(nxt)) continue;
				auto d = dfs(nxt, std::min(f, e.cap));
				if (d > 0) {
					e.cap -= d;
					graph.at(nxt).at(e.rev).cap += d;
					return d;
				}
			}
			level.at(crr) = -1;
			return Flow(0);
		}

	public:
		dinic (int n, int source, int sink):
			n(n), source(source), sink(sink), graph(n){}

		void insert(int u, int v, Flow c) {
			debug(u,v,c);
			graph.at(u).emplace_back(v, c, graph.at(v).size());
			graph.at(v).emplace_back(u, 0, graph.at(u).size() - 1);
		}

		auto build() {
			Flow ret = 0;
			while (true) {
				level.assign(n, -1);
				bfs();
				if (level.at(sink) == -1) return ret;
				ckd.assign(n, false);
				while (true) {
					auto f = dfs(source);
					if (f == 0) break;
					ret += f;
				}
			}
		}

		auto collect() const {
			std::vector<std::vector<flow_edge<Flow>>> ret(n);
			for (auto i = 0; i < n; i++) {
				for (auto const& e : graph.at(i)) {
					auto flow = e.original_cap - e.cap;
					if (flow > 0) ret.at(i).emplace_back(e.to, flow);
				}
			}
			return ret;
		}
};

int main() {
	std::cin.tie(0); std::cin.sync_with_stdio(false);
	int n; std::cin >> n;
	std::vector<lint> a(n+1,0);
	rep(i,1,n+1) {
		std::cin>> a.at(i);
	}
	debug(a);

	int s = 0, t = n + 1, N = n + 2;
	dinic<lint> dnc(N,s,t);
	rep(i,1,n+1) {
		lint x = a.at(i);
		if (x < 0) {
			dnc.insert(s,i,-x);
		} else if (0 < x) {
			dnc.insert(i,t,x);
		}
	}
	lint inf = std::numeric_limits<lint>::max();
	rep(d,1,n+1) {
		for (int i = 2 * d; i <= n; i += d) {
			dnc.insert(d,i,inf);
		}
	}

	lint full = 0;
	for (lint x : a) {
		if (0 < x) {
			full += x;
		}
	}
	lint cost = dnc.build();
	debug(full,cost);
	lint ans = full - cost;
	debug(dnc.collect());
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 384