#include<bits/stdc++.h>

using namespace std;

int N, a[109], need[109];
long long mini, currSum;

void back (int pos)
{
    if (pos > N / 3)
    {
        //cases ++;
        long long aux = currSum;
        for (int i=N / 2 + 1; i<=N; i++)
            if (need[i])
                aux += a[i];
            else
                aux += (a[i] <= 0 ? a[i] : 0);
        for (int i=N / 3 + 1; i<=N / 2; i++)
        {
            int j = 2 * i;
            if (need[i]) aux += a[i];
            else
            if (need[j] || a[j] <= 0) aux += (a[i] <= 0 ? a[i] : 0);
            else aux += (a[i] + a[j] <= 0 ? a[i] + a[j] : 0);
        }
        if (aux < mini)
            mini = aux;
        return ;
    }
    if (need[pos] > 0) currSum += a[pos], back (pos + 1), currSum -= a[pos];
    else
    {
        back (pos + 1);
        currSum += a[pos];
        for (int i=pos * 2; i<=N; i+=pos)
            need[i] ++;
        back (pos + 1);
        currSum -= a[pos];
        for (int i=pos * 2; i<=N; i+=pos)
            need[i] --;
    }
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N);
for (int i=1; i<=N; i++)
    scanf ("%d", &a[i]);
back (1);
//printf ("%d\n", cases);
long long ans = -mini;
for (int i=1; i<=N; i++)
    ans += a[i];
printf ("%lld\n", ans);
return 0;
}
