Problem:
Score : 700 points

Problem Statement

We have N gemstones labeled 1 through N.

You can perform the following operation any number of times (possibly zero).

Select a positive integer x, and smash all the gems labeled with multiples of x.

Then, for each i, if the gem labeled i remains without getting smashed, you will receive a_i yen (the currency of Japan).
However, a_i may be negative, in which case you will be charged money.

By optimally performing the operation, how much yen can you earn?

Constraints

All input values are integers.

1 \leq N \leq 100

|a_i| \leq 10^9

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

Print the maximum amount of money that can be earned.

Sample Input 1

6
1 2 -6 4 5 3

Sample Output 1

12

It is optimal to smash Gem 3 and 6.

Sample Input 2

6
100 -100 -100 -100 100 -100

Sample Output 2

200

Sample Input 3

5
-1 -2 -3 -4 -5

Sample Output 3

0

It is optimal to smash all the gems.

Sample Input 4

2
-1000 100000

Sample Output 4

99000

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 0x3fffffff;


ll N, a[105];
ll solve(vector<ll> &v, int n){
	ll ret = 0;
	for(; n < N; n++){
		bool f = false;
		for(auto t: v) if(n % t == 0){ f = true; break; }
		if(f) continue;
		if(n * 6 <= N){
			chmin(ret, solve(v, n+1));
			auto nx = v;
			nx.push_back(n);
			chmin(ret, solve(nx, n+1));
		}else{
			auto dval = [&](int n, int m){
				for(auto t: v){
					if(t > m) break;
					if(t == m) return 0ll;
					if(m == 4 && t == 2) return 0ll;
				}
				if(n*m > N) return 0ll;
				return a[n*m];
			};
			ll d1 = a[n];
			ll d2 = dval(n,2);
			ll d3 = dval(n,3);
			ll d4 = dval(n,4);
			ll d5 = dval(n,5);
			ll sum = d1 + d2 + d3 + d4 + d5;
			if(sum > d2 + d4) continue;
			if(sum > d3) continue;
			if(sum > d4) continue;
			if(sum > d5) continue;
			if(sum >= 0) continue;
			ret += sum;
			v.push_back(n);
		}
	}
	return ret;
}

int main(){
	//ios_base::sync_with_stdio(0);
	ll ans = 0;

	cin >> N;
	rep(i,N) cin >> a[i+1];

	ll sum = 0;
	rep(i,N) sum += a[i+1];

	vector<ll> v;
	chmax(ans, sum-solve(v, 2));
	cout << ans << endl;

	return 0;
}