Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=105;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=2000000000;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}
#define int ll
int N;
int a[maxn];

struct edge{
	int to,cap,rev;
	edge(int _,int __,int ___):to(_),cap(__),rev(___){}
};

vector<edge> G[maxn];

void add_edge(int u,int v,int c){
	//cout<<u<<' '<<v<<' '<<c<<'\n';
	G[u].pb(edge(v,c,SZ(G[v])));
	G[v].pb(edge(u,0,SZ(G[u])-1));
}

int lvl[maxn];
int iter[maxn];

vector<int> q;
int pt;
void bfs(int u){
	REP(i,N) lvl[i]=-1;
	lvl[u]=0;
	q.clear();
	q.pb(u);
	pt=0;
	while(pt<SZ(q)){
		int cur=q[pt++];
		for(edge &e:G[cur]){
			if(lvl[e.to]!=-1||e.cap<=0) continue;
			lvl[e.to]=lvl[cur]+1;
			q.pb(e.to);
		}
	}
}
int dfs(int s,int t,int f){
	if(s==t) return f;
	for(int &i=iter[s];i<SZ(G[s]);i++){
		edge &e=G[s][i];
		if(e.cap>0&&lvl[e.to]>lvl[s]){
			int d=dfs(e.to,t,min(f,e.cap));
			if(d>0){
				e.cap-=d;
				G[e.to][e.rev].cap+=d;
				return d;
			}
		}
	}
	return 0;
}

int dinic(int s,int t){
	int flow=0;
	while(1){
		bfs(s);
		REP(i,N) iter[i]=0;
		if(lvl[t]==-1) return flow;
		int f;
		while((f=dfs(s,t,INF))>0) flow+=f;
	}
}

int32_t main()
{
	int n;
	cin>>n;
	N=n+2;
	REP(i,n) cin>>a[i];
	int ans=0;
	REP(i,n) ans+=max(a[i],0);
	REP(i,n){
		if(a[i]<0) add_edge(n,i,-a[i]);
		if(a[i]>0) add_edge(i,n+1,a[i]);
	}
	for(int i=1;i<=n;i++) for(int j=2*i;j<=n;j+=i){
		add_edge(i-1,j-1,INF);
	}
	cout<<ans-dinic(n,n+1);
}




Compiler output:
a.cc: In function 'int32_t main()':
a.cc:122:26: error: no matching function for call to 'max(ll&, int)'
  122 |         REP(i,n) ans+=max(a[i],0);
      |                       ~~~^~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:122:26: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
  122 |         REP(i,n) ans+=max(a[i],0);
      |                       ~~~^~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:122:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  122 |         REP(i,n) ans+=max(a[i],0);
      |                       ~~~^~~~~~~~