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<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vector<ll> a(n);
	REP(i,n) cin>>a[i];
	FOR(i,2,min(n+2,14ll)) {
		FOR(j,n/i+1,n/(i-1)+1) {
			vector<ll> b(i-1);
			REP(k,i-1) b[k]=a[j*(k+1)-1];
			vector<bool> used;
			ll crt=-(INF*INF);
			REP(bit,(1ll<<(i-1))) {
				vector<bool> d(i-1,false);
				ll buf=bit;
				REP(k,(i-1)) {
					if(buf%2) d[k]=true;
					buf/=2;
				}
				ll sum=0;
				vector<bool> used2(i-1,false);
				REP(k,(i-1)) {
					bool det=true;
					REP(l,(i-1)) {
						if((k+1)%(l+1)==0&&d[l]) det=false;
					}
					if(det) sum+=b[k];
					used2[k]=det;
				}
				if(sum>crt) {
					crt=sum;
					used=used2;
				}
			}
			REP(k,i-1) {
				if(!used[k]) a[j*(k+1)-1]=0;
			}
		}
	}
	ll sz=n/9+1;
	ll crt=-(INF*INF);
	REP(bit,(1ll<<sz)) {
		vector<bool> d(sz,false);
		ll buf=bit;
		REP(i,sz) {
			if(buf%2) d[i]=true;
			buf/=2;
		}
		ll sum=0;
		REP(i,n) {
			bool det=true;
			REP(j,sz) {
				if((i+1)%(j+1)==0&&d[j]) det=false;
			}
			if(det) sum+=a[i];
		}
		if(sum>crt) {
			crt=sum;
		}
	}
	cout<<crt<<endl;
}