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 Rust (1.15.1) (judge verdict: Wrong Answer)

use std::io::stdin;
use std::cmp::min;
use std::cmp::max;

fn main(){
    let n: usize = getvec()[0];
    let xs_temp: Vec<i64> = getvec();
    let mut xs: Vec<i64> = vec![0];
    for x in xs_temp { xs.push(x); }
    let mut ans = 0;
    let m: usize = min(n, 10);

    for i in 0..2u64.pow(m as u32) {
        let mut temp = 0;
        let mut bs: Vec<bool> = Vec::new();
        for _ in 0..n+1 { bs.push(true); }
        for j in 1..n+1 as usize  {
            for k in 1..m+1 {
                if j % k == 0 && getbit(i, k) {
                    bs[j] = false;
                    break;
                }
            }
        }
        for j in m+1..n+1 {
            let mut xxx = 0;
            for k in 1..n/j + 1 {
                if bs[k*j] { xxx += xs[k*j]; }
            }
            if xxx < 0 {
                bs[j] = false;
            }
        }
        for j in 1..n+1 {
            if bs[j] { temp += xs[j]; }
        }
        /*
        if temp > ans {
            println!("{}", i);
            println!("{}", temp);
            for j in 1..n+1{
                print!("{} ", bs[j as usize]);
            }
            println!("\n");
        }
        */
        ans = max(temp, ans);
    }
    println!("{}", ans);
}

fn getbit(x: u64, i: usize) -> bool {
    return ((x << 1) >> i) % 2 > 0;
}

#[allow(dead_code)]
fn getline() -> String {
    let mut s = String::new();
    match stdin().read_line(&mut s){
        Ok(_) => {s.trim().to_string()}
        Err(_) => String::new()
    }
}

#[allow(dead_code)]
fn getvec<T: std::str::FromStr>() -> Vec<T>{
    let line = getline();
    line.split_whitespace().filter_map(|x| x.parse().ok()).collect()
}

#[allow(dead_code)]
fn getpair() -> (usize, usize){
    let nm = getvec();
    (nm[0], nm[1])
}