#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <vector>
#include <cassert>
#include <random>

using namespace std; using ll=long long; const ll LNF=1e18; const int INF = 1e9;
typedef pair<int,int> P;

void chmax(ll& x, ll y) {if (x<y) x=y;}

struct solver {
  int n; ll a[101]; bool done[101]={}; ll an = -LNF; bool pp = false;
  void input() {
    cin>>n; for(int i=1;i<=n;i++) cin>>a[i];
    //for(int i=1;i<=n;i++) a[i]=i * (2 * (i*5%3!=0) - 1);
  }
  void solve(int x) {
    if (x == n+1) {
      ll sm=0;
      for(int i=1;i<=n;i++) sm+=a[i] * !done[i];
      an = max(an, sm);
      return;
    } else if (done[x]) {
      solve(x+1); return;
    } else if (n / x == 1 || n / x == 2 && done[2*x] || n / x == 3 && done[2*x] && done[3*x]) {
      if (a[x] > 0) solve(x+1);
      else done[x]=true, solve(x+1), done[x]=false;
      return;
    } else if (n / x == 2 || n / x == 3 && done[3*x]) {
      // これが大きいほどいい
      ll s1 = 0, s2 = a[x], s3 = a[x] + a[2*x];
      // {1,2}, {2}, {}
      if (s1 >= s2 && s1 >= s3) {
        done[x]=done[2*x]=true; solve(x+1);
        done[x]=done[2*x]=false; return;
      } else if (s2 >= s1 && s2 >= s3) {
        // 2xのみ
        done[2*x]=true; solve(x+1); done[2*x]=false; return;
      } else {
        solve(x+1); return;
      }
    } else if (n / x == 3) {
      bool ot = (3*x%2==0) & (!done[3*x/2]); // 下側から現れる
      if (ot) {
        if (done[2*x]) {
          //134
          ll s[5] = {0, a[3*x/2], a[x], a[x] + a[3*x/2], a[x] + a[3*x/2] + a[3*x]};
          // {}, 4, 1, 14, 134
          auto it = max_element(s,s+5);
          switch(it-s) {
            case 0:
              done[x]=done[3*x]=done[3*x/2]=true;
              solve(x+1);
              done[x]=done[3*x]=done[3*x/2]=false;
              break;
            case 1:
              done[x]=done[3*x]=true; solve(x+1); done[x]=done[3*x]=false; break;
            case 2:
              done[3*x]=done[3*x/2]=true; solve(x+1); done[3*x]=done[3*x/2]=false; break;
            case 3:
              done[3*x]=true; solve(x+1); done[3*x]=false; break;
            case 4:
              solve(x+1); break;
          }
          return;
        } else {
          //1234
          int x4 = 3*x/2;
          ll s[8]={0, a[x4], a[x] + a[x4], a[x], a[x] + a[2*x] + a[x4], a[x] + a[2*x], a[x] + a[3*x] + a[x4], a[x] + a[2*x] + a[3*x] + a[x4]};
          // {1,2,3,4}, {1,2,3}, {2,3}, {2,3,4}, {3}, {3,4}, {2}, {}
          auto it = max_element(s,s+8);
          switch(it-s) {
            case 0:
              done[x]=done[2*x]=done[3*x]=done[3*x/2]=true;
              solve(x+1);
              done[x]=done[2*x]=done[3*x]=done[3*x/2]=false;
              break;
            case 1:
              done[x]=done[2*x]=done[3*x]=true;
              solve(x+1);
              done[x]=done[2*x]=done[3*x]=false;
              break;
            case 2:
              done[2*x]=done[3*x]=true;
              solve(x+1);
              done[2*x]=done[3*x]=false;
              break;
            case 3:
              done[2*x]=done[3*x]=done[3*x/2]=true;
              solve(x+1);
              done[2*x]=done[3*x]=done[3*x/2]=false;
              break;
            case 4:
              done[3*x]=true; solve(x+1); done[3*x]=false; break;
            case 5:
              done[3*x]=done[x4]=true; solve(x+1); done[3*x]=done[x4]=false; break;
            case 6:
              done[2*x]=true; solve(x+1); done[2*x]=false; break;
            case 7:
              solve(x+1); break;
          }
          return;
        }
      } else if (done[2*x]) {
        // 13
        ll s1 = 0, s2 = a[x], s3 = a[x] + a[3*x];
        if (s1 >= s2 && s1 >= s3) {
          done[x]=done[3*x]=true; solve(x+1);
          done[x]=done[3*x]=false; return;
        } else if (s2 >= s1 && s2 >= s3) {
          // 2xのみ
          done[3*x]=true; solve(x+1); done[3*x]=false; return;
        } else {
          solve(x+1); return;
        }
      } else {
        // 123
        ll s1 = 0, s2 = a[x], s3 = a[x] + a[2*x], s4 = a[x] + a[2*x] + a[3*x], s5 = a[x] + a[3*x];
        // {1,2,3}, {2,3}, {3}, {}, {2}
        if (s1 >= s2 && s1 >= s3 && s1 >= s4 && s1 >= s5) {
          done[x]=done[2*x]=done[3*x]=true; solve(x+1);
          done[x]=done[2*x]=done[3*x]=false; return;
        } else if (s2 >= s1 && s2 >= s3 && s2 >= s4 && s2 >= s5) {
          done[2*x]=done[3*x]=true; solve(x+1); done[2*x]=done[3*x]=false; return;
        } else if (s3 >= s1 && s3 >= s2 && s3 >= s4 && s2 >= s5) {
          done[3*x]=true; solve(x+1); done[3*x]=false; return;
        } else if (s4 >= s1 && s4 >= s2 && s4 >= s3 && s4 >= s5) {
          solve(x+1); return;
        } else {
          done[2*x]=true; solve(x+1); done[2*x]=false; return;
        }
      }
    }
    solve(x+1);
    bool done2[n+1]; 
    for(int i=x;i<=n;i+=x) {
      done2[i]=done[i]; done[i]=true;
    }
    solve(x+1);
    for(int i=x;i<=n;i+=x) {
      done[i]=done2[i];
    }
  }
  void output() {
    solve(1);
    cout << an << endl;
  }
  void print() {
  }
};

int main() {
  solver ss; 
  ss.input();
  ss.output();
  //ss.print();
}

Measured memory_bytes: 384