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# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
using System.IO;
public class CodeForces
{
#if TEST
// To set this go to Project -> Properties -> Build -> General -> Conditional compilation symbols: -> enter 'TEST' into text box.
const bool testing = true;
#else
    const bool testing = false;
#endif

    private static int Next()
    {
        int c;
        int res = 0;
        do
        {
            c = reader.Read();
            if (c == -1)
                return res;
        } while (c < '0' || c > '9');
        res = c - '0';
        while (true)
        {
            c = reader.Read();
            if (c < '0' || c > '9')
                return res;
            res *= 10;
            res += c - '0';
        }
    }
    private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024 * 10), Encoding.ASCII, false, 1024 * 10);
    private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), Encoding.ASCII, 1024 * 10);

    static void program(TextReader input)
    {
        var n = int.Parse(input.ReadLine());
        //for(var T = 0; T < t; T++)
        //{
        var data = input.ReadLine().Split(' ').Select(long.Parse).ToList();
        var removed = new bool[n];

        var win = data.Sum();
        for (var i = n - 1; i >= 0; i--)
        {
            var div = i + 1;
            long posWin = 0;
            for (var k = div; k - 1 < data.Count; k+=div)
            {
                if (!removed[k-1])
                {
                    posWin -= data[k-1];
                }
            }
            if (posWin > 0)
            {
                for (var k = div; k- 1 < data.Count; k += div)
                {
                    removed[k-1] = true;
                }
                win = Math.Max(win, win + posWin);
            }
        }
        Console.WriteLine(win);
        //}
        
        
    }

    public static void Main(string[] args)
    {
        if (!testing)
        { // set testing to false when submiting to codeforces
            program(Console.In); // write your program in 'program' function (its your new main !)
            return;
        }

        Console.WriteLine("Test Case(1) => expected :");
        Console.WriteLine("2\n");
        Console.WriteLine("Test Case(1) => found    :");
        program(new StringReader("abacaba\n"));
        Console.WriteLine();

        Console.WriteLine("Test Case(2) => expected :");
        Console.WriteLine("1\n");
        Console.WriteLine("Test Case(2) => found    :");
        program(new StringReader("zzzzz\n"));
        Console.WriteLine();

        Console.WriteLine("Test Case(3) => expected :");
        Console.WriteLine("3\n");
        Console.WriteLine("Test Case(3) => found    :");
        program(new StringReader("abcde\n"));
        Console.WriteLine();

    }
}