#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
// #define int ll
// #define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());const int D=4,dx[]={+1,0,-1,0},dy[]={0,+1,0,-1};
const int N=101;
int a[N];
int n,k;
ll mem[N][512];
bool ismem[N][512];
int u[N];
ll fun(int i
// ,int print=0
    ){
    int c=n/i;
    int mk=0;
    for(int j=1;j*i<=n;++j){
        if(u[j*i])mk|=1<<(j-1);
    }
    if(!ismem[i][mk]
        // ||print
        ){
        int mas[10]={0};
        for(int j=1;j*i<=n;++j){
            if(u[j*i])continue;
            mas[j]=a[j*i];
            // if(print)dbg(j,mas[j]);
        }
        ll al=0;
        for(int j=1;j<=c;++j)al+=mas[j];
        ll x=min(al,0ll);
        ll cur=0;
        cur+=min(mas[5],0);
        cur+=min(mas[7],0);
        //ne berem 3
        cur+=min(mas[9],0);
        //ne berem 2,4
        cur+=min(mas[6],0);
        cur+=min(mas[8],0);
        upn(x,cur);
        cur-=min(mas[8],0);
        //berem 4
        cur+=mas[4]+mas[8];
        upn(x,cur);
        //berem 2
        cur-=min(mas[6],0);
        cur+=mas[2]+mas[6];
        upn(x,cur);
        //berem 2&3
        cur-=min(mas[9],0);
        cur+=mas[3]+mas[9];
        upn(x,cur);
        //berem 3
        cur-=mas[2];
        upn(x,cur);
        cur-=mas[4];
        upn(x,cur);
        cur-=mas[8];
        upn(x,cur);

        ismem[i][mk]=1,mem[i][mk]=x;
    }
    return mem[i][mk];
}
ll ans=0,tot=0;
vector<int> v={2,3,4,5,6,7,8,9,10,12,14,15,16,18,20,21,22,24,26,28,30,32};
vector<int> resh;
void rec(int bit){
    if(bit==k){
        ll pot=tot;
        for(int j=1;j<=n;++j)if(u[j])pot-=a[j];
        for(int i:resh){
            if(u[i])continue;
            // if(i+i-1>=n){
            //     pot-=min(a[i],0);
            // }else{
            pot-=fun(i);
            // }
        }
        // if(pot>ans){
        //     dbg(pot);
        //     for(int j=1;j<=n;++j)dbg(j,u[j]);
        //     for(int i:resh){
        //         if(u[i])continue;
        //         dbg(i);
        //         dbg(fun(i,1));
        //     }
        // }
        upx(ans,pot);
    }else{
        rec(bit+1);
        for(int i=v[bit];i<=n;i+=v[bit])u[i]++;
        rec(bit+1);
        for(int i=v[bit];i<=n;i+=v[bit])u[i]--;
    }
}
int32_t main(){
    cin>>n;
    for(int j=11;j<=n;++j){
        int ok=1;
        for(int i:v)if(j==i)ok=0;
        for(int i:resh)if(j%i==0)ok=0;
        if(ok)resh.pb(j);
    }
    while(!v.empty()&&v.back()>n)v.pop_back();
    while(!resh.empty()&&resh.back()>n)resh.pop_back();
    k=sz(v);
    for(int i=1;i<=n;++i){
        cin>>a[i];
        tot+=a[i];
        // if(i+i-1>=n)lat+=min(a[i],0)
    }
    rec(0);
    cout<<ans<<'\n';

    return 0;
}

Measured memory_bytes: 3884