#include <bits/stdc++.h>
#define int ll
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v){stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modpow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isprime(ll n){if(n<2)return 0;if(!(n%2))return !(n-2);lll d=n-1,t,y;while(!(d%2))d>>=1;vl al={2,325,9375,28178,450775,9780504,1795265022};for(ll a:al){if(n<=a)break;t=d,y=modpow(a,t,n);while(t!=n-1&&y!=1&&y!=n-1)y=y*y%n,t<<=1;if(y!=n-1&&!(t%2))return 0;}return 1;}
void dout(double d){printf("%.12f\n",d);}
void YN(bool z){cout<<(z?"YES\n":"NO\n");}
void Yn(bool z){cout<<(z?"Yes\n":"No\n");}
void yn(bool z){cout<<(z?"yes\n":"no\n");}
constexpr int iinf = 1e9+6;
constexpr ll linf = 1e18;
constexpr int mod = 1e9+7;
constexpr double pi = acos(-1);
constexpr double eps = 1e-10;

class Dinic {
  private:
    struct Edge {
      int to, cap, rev;
      Edge(int t, int c, int r) :to(t), cap(c), rev(r) {}
    };
    int V;
    std::vector<std::vector<Edge>> graph;
    std::vector<int> level, iter;

  public:
    Dinic(int v) : V(v) {
      graph.resize(v);
      level.resize(v, -1);
      iter.resize(v, 0);
    }
    // fromからtoへ向かう容量capの辺をグラフに追加する
    void add_edge(int from, int to, int cap) {
      graph[from].emplace_back(to, cap, graph[to].size());
      graph[to].emplace_back(from, 0, graph[from].size() - 1);
    }

    // sからの最短距離をBFSで計算する
    void bfs(int s) {
      std::fill(level.begin(), level.end(), -1);
      std::queue<int> queue;
      level[s] = 0;
      queue.push(s);
      while (!queue.empty()) {
        int v = queue.front(); queue.pop();
        for (int i = 0; i < graph[v].size(); ++i) {
          Edge& e = graph[v][i];
          if (e.cap > 0 && level[e.to] < 0) {
            level[e.to] = level[v] + 1;
            queue.push(e.to);
          }
        }
      }
    }

    // 増加パスをDFSで探す
    int dfs(int v, int t, int f) {
      if (v == t) return f;
      for (int& i = iter[v]; i < graph[v].size(); ++i) {
        Edge& e = graph[v][i];
        if (e.cap > 0 && level[v] < level[e.to]) {
          int d = dfs(e.to, t, std::min(f, e.cap));
          if (d > 0) {
            e.cap -= d;
            graph[e.to][e.rev].cap += d;
            return d;
          }
        }
      }
      return 0;
    }

    // sからtへの最大流を求める
    int run(int s, int t) {
      int res = 0;
      while (true) {
        bfs(s);
        if (level[t] < 0) return res;
        std::fill(iter.begin(), iter.end(), 0);
        int f;
        while ((f = dfs(s, t, linf)) > 0) {
          res += f;
        }
      }
    }
};

int n, a;

main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  Dinic d(n+2);
  ll ans = 0;
  FOR(i, 1, n+1){
    cin >> a;
    if(a > 0){
      ans += a;
      d.add_edge(i, n+1, a);
    }
    if(a < 0){
      d.add_edge(0, i, -a);
    }
    for(int j = i*2; j <= n; j += i) d.add_edge(i, j, 1e14);
  }
  cout << ans - d.run(0, n+1) << endl;
  return 0;
}

Measured memory_bytes: 256