#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdio>
#include <complex>
#include <numeric>
#include <string.h>
#include <random>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.141592653589793238462643383279;
const double EPS = 1e-9;
const ll MOD1 = 1000000007;
const ll MOD2 = 1000000021;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

int N;
ll A[101];
bool dead[101];
ll ans;

void dfs (int pos, ll now) {
    if (pos == N+1) {
        ans = max(ans, now);
        return;
    }
    if (dead[pos]) {
        dfs(pos+1, now);
        return;
    }
    dfs(pos+1, now+A[pos]);
    if (A[pos] >= 0) return;
    bool tmp[100];
    for (int i = pos; i <= N; i++) tmp[i] = dead[i];
    for (int i = pos; i <= N; i += pos) {
        dead[i] = true;
    }
    ll cnt = 0;
    for (int i = pos; i <= N; i++) {
        if (!dead[i] && A[i] > 0) cnt += A[i];
    }
    if (now+cnt > ans) dfs(pos+1, now);
    for (int i = pos; i <= N; i++) dead[i] = tmp[i];
}

int main() {
    cin >> N;
    rep(i,N) cin >> A[i+1];
    dfs(1, 0);
    cout << ans << endl;
}