#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <limits.h>
#include <assert.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <bitset>
#include <vector>
using namespace std;

#define LL long long

#define fi first
#define se second
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(a,b) (((a)+(b))>>1)
#define maxx(a,b) ((a)<(b)?(b):(a))
#define minx(a,b) ((a)<(b)?(a):(b))
#define absx(a) ((a)<0?-(a):(a))
#define mk(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define itr iterator
#define lowbit(x) ((x)&-(x))

typedef unsigned LL ULL;
typedef unsigned uint;
typedef map<int,int> mii;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<LL,LL> pLL;

template< typename T > inline void read(T &x) {
    bool f; char ch; f=0; x=0; ch=getchar();
    while(ch<'0' || ch>'9') {if(ch=='-') f=1; ch=getchar();}
    while(ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();}
    if(f) x=-x;
}

template< typename T > inline void Max(T &a, T b) {if(a<b) a=b;}
template< typename T > inline void Min(T &a, T b) {if(b<a) a=b;}
template< typename T > inline T Abs(T a) {if(a<0) return -a; else return a;}

const double pi=(double) acos(-1.0);
const int MOD=(int) 1e9+7;
const int INF=(int) 0x3f3f3f3f;
const LL  LINF=(LL) INF<<32|INF;
const int SINF=(uint) ~0>>1;
const LL  SLINF=(ULL) (-1)>>1;
const double DINF=(double) 1e50;
const double eps=(double) 1e-8;
const int maxn=(int) 2000+20;
const int maxm=(int) 1e5+20;
const int maxk=(int) 5e2+20;

inline int sig(double x) {return x<-eps?-1:x>eps;}

//--------------start------------------

const int N=(int) 1e2+20;
struct Dinic
{
    struct Edge
    {
        int from,to;
        LL cap,flow;
        Edge() {}
        Edge(int _from,int _to,LL _cap,LL _flow):from(_from),to(_to),cap(_cap),flow(_flow) {}
    };
    int n,m,s,t;
    vector<Edge> edge;
    vector<int> G[N];
    bool vis[N];
    int d[N],cur[N];

    void init(int _n,int _s,int _t)
    {
        n=_n; s=_s; t=_t;
        m=0;
        for(int i=0;i<=n;i++) G[i].clear();
        edge.clear();
    }

    void add_edge(int from,int to,LL cap)
    {
        edge.push_back(Edge(from,to,cap,0));
        edge.push_back(Edge(to,from,0,0));
        m+=2;
        G[from].push_back(m-2);
        G[to].push_back(m-1);
    }

    bool BFS()
    {
        memset(vis,0,sizeof(vis));
        queue<int> Q;
        Q.push(s);
        d[s]=0;
        vis[s]=1;
        while(!Q.empty())
        {
            int x=Q.front(); Q.pop();
            for(int i=0;i<G[x].size();i++)
            {
                Edge &e=edge[G[x][i]];
                if(!vis[e.to] && e.cap>e.flow)
                {
                    vis[e.to]=1;
                    d[e.to]=d[x]+1;
                    Q.push(e.to);
                }
            }
        }
        return vis[t];
    }

    LL DFS(int x,LL a)
    {
        if(x==t || a==0) return a;
        LL flow=0, f;
        for(int &i=cur[x];i<G[x].size();i++)
        {
            Edge &e=edge[G[x][i]];
            if(d[x]+1==d[e.to] && (f = DFS(e.to,min(a,e.cap-e.flow)))>0)
            {
                e.flow+=f;
                edge[G[x][i]^1].flow-=f;
                flow+=f;
                a-=f;
                if(a==0) break;
            }
        }
        return flow;
    }

    LL Maxflow()
    {
        LL res=0;
        while(BFS())
        {
            memset(cur,0,sizeof(cur));
            res+=DFS(s,LINF);
        }
        return res;
    }
}MF;

int n;
int a[maxn];

void work()
{
    read(n);
    for(int i=1;i<=n;i++) read(a[i]);

    MF.init(n+1,0,n+1);
    LL ans=0;
    for(int i=1;i<=n;i++)
    {
        if(a[i]<0)
        {
            MF.add_edge(0,i,-a[i]);
        }
        else
        {
            ans+=a[i];
            MF.add_edge(i,n+1,a[i]);
        }

        for(int j=i+i;j<=n;j+=i) MF.add_edge(i,j,LINF);
    }
    ans-=MF.Maxflow();
    cout <<ans <<endl;
}

//--------------end--------------------

int main()
{
#ifdef yukihana0416
freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
#endif // yukihana0416
    work();
    return 0;
}


Measured memory_bytes: 256