import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math;


void main()
{
    auto N = readln.chomp.to!int;
    auto AS = [0L] ~ readln.split.to!(long[]);

    foreach_reverse (i, a; AS) {
        if (!i) continue;
        long sum;
        foreach (j, b; AS) if (j % i == 0) sum += b;
        if (sum < 0) {
            foreach (j, ref b; AS) if (j % i == 0) b = 0;
        }
    }
    writeln(AS.sum);
}