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>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<int,pi> pii;
typedef vector<pi> vpi;
typedef set<int> si;
typedef long double ld;
#define mp make_pair
#define pb push_back
#define f first
#define s second
int INF = 1e9;
ll MOD = 1e9;
#define lb lower_bound
#define ub upper_bound
#define SZ(x) (int)x.size()
#define ALL(x) x.begin(),x.end()

int N;
int A[110];
ll ans, l, T;
int with2[] = {3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33};
int with3[] = {4,5,7,8,10,11,13,14,16,17,19,20,22,23,25};
int with4[] = {5,6,7,9,10,11,13,14,15,17,18,19};
int none[] = {5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};

int len2 = (1<<16);
int len3 = (1<<15);
int len4 = (1<<12);
int lennon = (1<<16);

int tmp[110];

vi factors[110];

int main(){
  // freopen("in.txt","r",stdin);
  cin >> N;
  for (int i=1;i<=N;++i)cin>>A[i];
  for (int i=1;i<=N;++i)l += A[i];
  for (int i=1;i<=100;++i){
    for (int j=i;j<=100;j+=i)factors[i].pb(j);
  }

  ans = 0;

  for (int i=2;i<=100;i+=2)T += A[i];

  for (int bm = 0; bm < len2; ++bm){
    for (int i=1;i<=100;i+=2)tmp[i] = 0;
    for (int t = 0; t <= 15; ++t){
      if ((1<<t) & bm){
        for (auto it : factors[with2[t]])if(it%2 != 0)tmp[it] = 1;
      }
    }
    ll t = T;
    for (int i=1;i<=N;++i)if(tmp[i])t += A[i];
    for (int i=33;i<=N;++i){
      t = t + min(0, A[i]);
    }
    ans = min(ans, t);
  }
  cout<<l-ans;
}