#include <iostream>
#include <vector>
#include <cstring>

using namespace std;
typedef long long ll;

const ll INF =  1e+12;

struct edge {ll to, cap, rev;};

vector<edge> G[202];
bool used[202];

void add_edge(ll from, ll to, ll cap){
    G[from].push_back((edge{to, cap, (ll)G[to].size()}));
    G[to].push_back((edge{from, 0, (ll)G[from].size()-1}));
}

ll dfs(ll v, ll t, ll f, vector<edge> G[]){
    if(v == t) return f;
    used[v] = true;
    for(ll i = 0; i < G[v].size(); i++){
        edge &e = G[v][i];
        if(!used[e.to] && e.cap > 0){
            ll d = dfs(e.to, t, min(f, e.cap), G);
            if(d > 0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

ll N, a[100];

int main(){
    cin >> N;
    for(int i = 0; i < N; i++) cin >> a[i];
    ll flow = 0;
    for(int i = 1; i < N; i++) {
        if(a[i] >= 0){
            add_edge(0, i, a[i]);
        }
        else {
            add_edge(i, N, -a[i]);
        }
    }
    for(int i = 1; i < N; i++) {
        for(int j = i+1; j < N; j++) {
            if((j+1)%(i+1) == 0) add_edge(j, i, INF);
        }
    }
    int s = 0, t = N;
    ll ans = a[0];
    for(int i = 1; i < N; i++) {
        if(a[i] >= 0) ans += a[i];
    }
    while(true){
        memset(used, 0, sizeof(used));
        ll f = dfs(s, t, INF, G);
        if(f == 0){
            break;
        }
        flow += f;
    }
    if(flow >= INF){
        cout << -1 << endl;
    }else{
        cout << max((ll)0, -flow+ans) << endl;
    }
}