Language: C++

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
template<class V> struct MaxFlow { // Dinic O(V^2E)
    struct edge { int to, reve; V cap; edge(int t, int r, V c) : to(t), reve(r), cap(c) {} };
    int MV; vector<vector<edge>> E; vector<int> itr, lev;
    MaxFlow(int n) { init(n); } MaxFlow() { }
    void init(int n) { MV = n; itr = vector<int>(MV), lev = vector<int>(MV); E = vector<vector<edge>>(MV); }
    void add_edge(int x, int y, V cap, bool undir = false) {
        E[x].push_back(edge(y, (int)E[y].size(), cap));
        E[y].push_back(edge(x, (int)E[x].size() - 1, undir ? cap : 0));
    }
    void bfs(int cur) {
        rep(i, 0, MV) lev[i] = -1; queue<int> q; lev[cur] = 0; q.push(cur);
        while (q.size()) {
            int v = q.front(); q.pop();
            for (auto e : E[v]) if (e.cap>0 && lev[e.to]<0) lev[e.to] = lev[v] + 1, q.push(e.to);
        }
    }
    V dfs(int from, int to, V cf) {
        if (from == to)return cf; for (; itr[from]<E[from].size(); itr[from]++) {
            edge* e = &E[from][itr[from]]; if (e->cap>0 && lev[from]<lev[e->to]) {
                V f = dfs(e->to, to, min(cf, e->cap)); if (f>0) { e->cap -= f; E[e->to][e->reve].cap += f; return f; }
            }
        } return 0;
    }
    V maxflow(int from, int to) {
        V fl = 0, tf; while (1) {
            bfs(from); if (lev[to]<0) return fl;
            rep(i, 0, MV)itr[i] = 0; while ((tf = dfs(from, to, numeric_limits<V>::max()))>0) fl += tf;
        }
    }
};
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　 |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/



template<typename T> struct PSP {
    MaxFlow<T> mf;
    vector<T> p;
    vector<tuple<int, int, T>> xyz;
    int NV;
    PSP() {}
    PSP(int _NV) { init(_NV); }
    void init(int _NV) { NV = _NV; p.resize(N); }
    void setp(int i, T v) { p[i] = v; }
    void setxyz(int x, int y, T z) { xyz.push_back(make_tuple(x, y, z)); }
    T solve() {
        mf.init(N + 2);
        int s = N, t = N + 1;

        T res = 0;
        rep(i, 0, N) {
            if (p[i] < 0) mf.add_edge(s, i, -p[i]);
            else {
                res += p[i];
                mf.add_edge(i, t, p[i]);
            }
        }
        fore(t, xyz) {
            int x, y; T z;
            tie(x, y, z) = t;
            mf.add_edge(x, y, z);
        }
        
        res -= mf.maxflow(s, t);
        return res;
    }
};






int N, A[101];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N) cin >> A[i];

    PSP<ll> psp(N);
    rep(i, 0, N) psp.setp(i, A[i]);
    rep(i, 0, N) rep(j, i + 1, N) {
        int a = i + 1;
        int b = j + 1;
        if (b % a == 0) psp.setxyz(i, j, inf);
    }
    cout << psp.solve() << endl;
}


Compiler output:
a.cc: In member function 'void PSP<T>::init(int)':
a.cc:61:45: error: 'N' was not declared in this scope
   61 |     void init(int _NV) { NV = _NV; p.resize(N); }
      |                                             ^
a.cc: In member function 'T PSP<T>::solve()':
a.cc:65:17: error: 'N' was not declared in this scope
   65 |         mf.init(N + 2);
      |                 ^