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)

#pragma comment(linker, "/STACK:60777216")  

#include <cassert>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<complex>
#include<vector>
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<string>
#include<cstdlib>
#include<memory.h>
#include<ctime>
#include<bitset>
#include<fstream>
#include<queue>
#include<stack>
#include<unordered_map>
#include<unordered_set>

using namespace std;

typedef long double ld;

typedef long long ll;
typedef pair<int,int>	pii;
typedef pair<ld,ld>	pdd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef pair<ll,ll> pl;

#define FOR(i,a,b)		for(int i=(a);i<(b);i++)
#define REP(i,n)		FOR(i,0,n)
#define SORT(v)			sort((v).begin(),(v).end())
#define UN(v)			SORT(v),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define CL(a,b)			memset(a,b,sizeof a)
#define pb				push_back

int n;
int a[111];
int b[111];
ll best=0;
int num;
const int LIM = 28;
void go(vi v,int next){
	if(next==LIM+1){
		REP(i,n){
			b[i]=a[i];
			REP(j,v.size())if((i+1)%v[j]==0)b[i]=0;
		}
		for(int i=50;i>LIM;i--){
			ll sm=0;
			for(int j=1;j*i<=n;j++)sm+=b[i*j-1];
			if(sm<0){
				for(int j=1;j*i<=n;j++)b[i*j-1]=0;
			}
		}
		//30 45
		if(b[30-1]+b[45-1]+b[90-1]<0){b[30-1]=b[45-1]=b[90-1]=0;}
		//32 48
		if(b[32-1]+b[48-1]+b[96-1]<0){b[32-1]=b[48-1]=b[96-1]=0;}

		ll t =0;
		REP(i,n)t+=b[i];
		best=max(best,t);
		return;
	}
	go(v,next+1);
	bool h = 0;
	REP(i,v.size())if(next%v[i]==0){h=1;break;}
	if(!h){
		v.pb(next);
		go(v,next+1);
	}
}

int gcd(int a,int b){
	while(a&&b)
		if(a>b)a%=b;
		else b%=a;
		return a+b;
}

int main(){	
#ifdef LocalHost
	freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
#endif

	
	cin>>n;
	//n=100;
	REP(i,n){
		cin>>a[i];
		//a[i]=0;
		if(i>=50 && a[i]<0)a[i]=0;
	}

	vi v;
	go(v,1);
	cout<<best<<endl;
	/*int t;
	FOR(i,21,51)FOR(j,i+1,51)if((t=i*j/gcd(i,j))<=100 && j%i!=0){
		num++;cout<<i<<' '<<j<<endl;

		FOR(k,j+1,51)if(t*k/gcd(t,k)<=100 && k%i!=0 && k%j!=0)cout<<i<<' '<<j<<' '<<k<<endl;
	}
	cout<<num<<endl;*/
	/*
	21 28
22 33
24 32
24 36
26 39
28 42
30 45
32 48
*/
#ifdef LocalHost
	printf("TIME: %.3lf\n",ld(clock())/CLOCKS_PER_SEC);
#endif
	return 0;
}