#include<bits/stdc++.h>
using namespace std;
using Int = long long;
Int n,ans=0;
vector<Int> a(202),u(202,0);
Int tmp=0;
const Int BEET = 35;
void dfs(Int x){
  //cout<<x<<endl;
  if(x==BEET){
    Int res=tmp;
    //cout<<res<<":"<<endl;
    for(Int i=BEET;i<=n;i++){
      //cout<<"i "<<i;
      if(u[i]) continue;
      if((i&1)==0&&BEET<=i/2) continue;
      if(i*2<=n&&!u[i*2]){
	// rm i / rm i*2 / get
	res+=max({0LL,a[i],a[i]+a[i*2]});
      }else{
	// rm / get
	res+=max({0LL,a[i]});
      }
    }
    //cout<<endl;
    ans=max(ans,res);
    return;
  }
  
  if(u[x]){
    dfs(x+1);
    return;
  }

  // get x
  tmp+=a[x];
  dfs(x+1);
  tmp-=a[x];

  // rm x and its mul
  for(Int i=x;i<=101;i+=x) u[i]++;
  dfs(x+1);
  for(Int i=x;i<=101;i+=x) u[i]--;
}
signed main(){
  cin>>n;
  for(Int i=1;i<=n;i++) cin>>a[i];

  //assert(n<BEET);
  dfs(1);
  cout<<ans<<endl;
  return 0;
}
