#include <bits/stdc++.h>

using namespace std;

//#define FILE_IO

typedef long long LL;
typedef pair<int, int> pii;
typedef pair<pii, int> p3i;

class EdmondsKarp
{
public:
    int N, S, T;
    vector <p3i> edges;
    int cp[105][105];
    int flw[105][105];
    vector <int> edg[105];
    int d[105], f[105];
    bool initGraph;

    EdmondsKarp()
    {
        N = S = T = 0;
        memset(cp, 0, sizeof(cp));
        memset(flw, 0, sizeof(flw));
        memset(d, 0, sizeof(d));
        memset(f, 0, sizeof(f));
        initGraph = false;
    }

    void addEdge(int x, int y, int c)
    {
        edges.push_back({{x, y}, c});
        initGraph = false;
    }

    void createGraph()
    {
        memset(cp, 0, sizeof(cp));

        N = 0;
        for(auto e: edges)
        {
            N = max(N, max(e.first.first, e.first.second));
            cp[e.first.first][e.first.second] += e.second;
        }

        for(int i = 1; i <= N; i++) edg[i].clear();
        for(int i = 1; i <= N; i++)
            for(int j = i + 1; j <= N; j++)
                if(cp[i][j] || cp[j][i])
                {
                    edg[i].push_back(j);
                    edg[j].push_back(i);
                }

        initGraph = true;
    }

    void BFS(int start)
    {
        for(int i = 1; i <= N; i++) d[i] = 0;
        d[start] = 1;
        queue <int> q;
        q.push(start);
        while(!q.empty())
        {
            int nod = q.front(); q.pop();
            for(auto nxt: edg[nod])
                if(!d[nxt] && cp[nod][nxt] - flw[nod][nxt])
                {
                    d[nxt] = 1 + d[nod];
                    f[nxt] = nod;
                    q.push(nxt);
                }
        }
    }

    int getFlow(int nod)
    {
        if(nod == S)    return (1 << 30);
        int ans = min( cp[ f[nod] ][nod] - flw[ f[nod] ][nod], getFlow(f[nod]) );
        return ans;
    }

    void pushFlow(int nod, int nxt, int flow)
    {
        flw[nod][nxt] += flow;
        flw[nxt][nod] -= flow;
        if(nod == S)    return;
        pushFlow(f[nod], nod, flow);
    }

    LL getMaxFlow(int _S, int _T)
    {
        S = _S; T = _T;

        if(!initGraph)  createGraph();

        memset(flw, 0, sizeof(flw));
        LL flow = 0;
        bool newFlow = true;
        while(newFlow)
        {
            newFlow = false;
            BFS(S);

            for(auto nod: edg[T])
                if(cp[nod][T] - flw[nod][T] && d[nod] != 0)
                {
                    int addFlow = getFlow(nod);
                    addFlow = min(addFlow, cp[nod][T] - flw[nod][T]);
                    if(addFlow)
                    {
                        pushFlow(nod, T, addFlow);
                        flow += addFlow;
                        newFlow = true;
                    }
                }
        }

        return flow;
    }

    vector<pii> getMinCut(int _S, int _T)
    {
        S = _S; T = _T;
        getMaxFlow(_S, _T);

        vector<pii> ans;
        BFS(S);
        for(auto e: edges)
        {
            int x = e.first.first;
            int y = e.first.second;
            if(d[x] != 0 && d[y] == 0 && cp[x][y] == flw[x][y])
                ans.push_back({x, y});
        }

        return ans;
    }
};

EdmondsKarp flow;

int N;
LL v[105];

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    cin >> N;
    for(int i = 1; i <= N; i++) cin >> v[i];

    for(int i = 1; i <= N; i++)
        for(int j = 2 * i; j <= N; j += i)
            flow.addEdge(i, j, 1 << 30);

    LL mx = 0;
    for(int i = 1; i <= N; i++)
    {
        if(v[i] >= 0)
        {
            mx += v[i];
            flow.addEdge(i, N + 2, v[i]);
        }
        else
        {
            flow.addEdge(N + 1, i, -v[i]);
        }
    }

    LL flw = flow.getMaxFlow(N + 1, N + 2);

    cout << mx - flw << '\n';

    return 0;
}


Measured memory_bytes: 384