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

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

    long[string] memo;
    long solve(int i, long[] rest) {
        if (i == N+1) return 0;
        
        auto n = rest[i];
        rest[i] = 0;
        auto key = rest.to!string;
        if (key in memo) return memo[key];
        rest[i] = n;

        auto r1 = rest[i] + solve(i+1, rest);

        long[] rest_;
        rest_.length = N+1;
        foreach (j, ref e; rest) if (j % i) rest_[j] = e;
        auto r2 = solve(i+1, rest_);

        return memo[key] = max(r1, r2);
    }

    writeln(solve(1, [0L] ~ AS));
}