Language: C++

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

template <class T>
class EdgeBase
{
public:
    int to, rev;
    T cap;
    EdgeBase(){};
    EdgeBase(int to0, T cap0){to = to0; cap = cap0;}
    EdgeBase(int to0, T cap0, int rev0){to = to0; cap = cap0; rev = rev0;}
};
typedef EdgeBase<long long> Edge;

template<class T>
T maxFlow(const vector<vector<EdgeBase<T> > >& edges0, int source, int sink)
{
    const T INF = numeric_limits<T>::max();
    const T EPS = static_cast<T>(1.0e-10);

    static vector<vector<EdgeBase<T> > > edges;
    static vector<bool> used;

    class Func{
    public:
        static T dfs(int s, int t, T f){
            if(s == t)
                return f;
            used[s] = true;
            for(auto& e : edges[s]){
                if(!used[e.to] && e.cap > EPS){
                    T g = dfs(e.to, t, min(f, e.cap));
                    if(g > EPS){
                        e.cap -= g;
                        edges[e.to][e.rev].cap += g;
                        return g;
                    }
                }
            }
            return 0;
        }
    };

    if(source == sink)
        return INF;

    int n = edges0.size();
    edges.assign(n, vector<EdgeBase<T> >());
    for(int i=0; i<n; ++i){
        for(const auto& e : edges0[i]){
            edges[i].push_back(EdgeBase<T>(e.to, e.cap, edges[e.to].size()));
            edges[e.to].push_back(EdgeBase<T>(i, 0, edges[i].size()-1));
        }
    }

    T ret = 0;
    for(;;){
        used.assign(n, false);
        T f = Func::dfs(source, sink, INF);
        if(f <= EPS)
            return ret;
        ret += f;
    }
}


int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; ++i)
        cin >> a[i];

    int source = 0;
    int sink = n + 1;
    vector<vector<Edge> > edges(n+2);
    long long ans = 0;
    for(int i=1; i<=n; ++i){
        edges[source].push_back(Edge(i, max(0, a[i-1])));
        edges[i].push_back(Edge(sink, max(0, -a[i-1])));
        ans += max(0, a[i-1]);
        for(int j=i*2; j<=n; j+=i)
            edges[j].push_back(Edge(i, LLONG_MAX/2));
    }

    ans -= maxFlow(edges, source, sink);
    cout << ans << endl;

    return 0;
}


Compiler output:
a.cc: In static member function 'static T maxFlow(const std::vector<std::vector<EdgeBase<T> > >&, int, int)::Func::dfs(int, int, T)':
a.cc:54:43: error: use of local variable with automatic storage from containing function
   54 |                 if(!used[e.to] && e.cap > EPS){
      |                                           ^~~
a.cc:42:13: note: 'const T EPS' declared here
   42 |     const T EPS = static_cast<T>(1.0e-10);
      |             ^~~
a.cc:56:28: error: use of local variable with automatic storage from containing function
   56 |                     if(g > EPS){
      |                            ^~~
a.cc:42:13: note: 'const T EPS' declared here
   42 |     const T EPS = static_cast<T>(1.0e-10);
      |             ^~~