#include <bits/stdc++.h>

using namespace std;

int n;
int a[110];
bitset<110> vis;
int mask[110];
int MAX;

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	cin >> n;

	for(int i = 1; i <= n; i++) cin >> a[i];

	MAX = min(n, 22);
	
	for(int i = 1; i <= n; i++){
		for(int j = 2; j <= MAX; j++){
			if(i % j == 0) mask[i] |= (1 << (j - 2));
		}
	}

	long long ans = 0;

	for(int bit = 0; bit < (1 << (MAX - 1)); bit++){
		vis = 0;
		for(int k = 1; k <= n; k++){
			if(mask[k] & bit) vis[k] = true;
		}

		for(int k = n; k > MAX; k--){
			long long sum = 0;

			for(int j = k; j <= n; j += k){
				if(vis[j]) continue;

				sum += a[j];
			}

			if(sum < 0){
				for(int j = k; j <= n; j += k){
					vis[j] = true;
				}
			}
		}

		long long sum = 0;
		for(int k = 1; k <= n; k++)
			if(!vis[k]) sum += a[k];

		ans = max(ans, sum);
	}

	cout << ans <<"\n";

	return 0;
}