Language: C++

#include<bits/stdc++.h>
#define inf 1000000000000ll
using namespace std;

struct edge{int go,next;long long s;} a[1000005];
int n,aa[1000],cnt,end[1100],f[1100],q[1100],s,t,id[1100],idd[1100];
long long td,ss,tdss;

inline void add(int u,int v,long long w){
	a[++cnt].go=v;a[cnt].s=w;a[cnt].next=end[u];end[u]=cnt;
	a[++cnt].go=u;a[cnt].s=0;a[cnt].next=end[v];end[v]=cnt;
}
inline bool bfs(){
	memset(f,-1,sizeof(f));
	int h=0,r=1;q[1]=s;f[s]=1;
	while (h<r){
		int now=q[++h];if (now==t) return 1;
		for (int i=end[now];i;i=a[i].next){
			int go=a[i].go;
			if (f[go]==-1&&a[i].s){
				f[go]=f[now]+1;
				q[++r]=go;
			}
		}
	}return 0;
}
long long dinic(int sta,long long sum){
	if (sta==t) return sum;long long os=sum;
	for (int i=end[sta];i&&os;i=a[i].next){
		int go=a[i].go;
		if (f[go]==f[sta]+1&&a[i].s){
			int minv=dinic(go,min(os,a[i].s));
			a[i].s-=minv;a[i^1].s+=minv;os-=minv;
		}
	}if (os==sum) f[sta]=-1;return sum-os;
}
int main(){
	scanf("%d",&n);cnt=1;
	for (int i=1;i<=n;i++){
		scanf("%d",&aa[i]);
		ss+=aa[i];
		aa[i]=-aa[i];
	}
	for (int i=1;i<=n;i++){
		for (int j=i*2;j<=n;j+=i){
			add(i,j,inf);
		}
	}
	for (int i=1;i<=n;i++){
		if (aa[i]>0){
			add(n+1,i,aa[i]);
			tdss+=aa[i];                         
		}
		else add(i,n+2,-aa[i]);
	}
	s=n+1;t=n+2;
	while (bfs()) td+=dinic(n+1,inf);
	printf("%lld",ss+(tdss-td));
}

Compiler output:
a.cc: In function 'void add(int, int, long long int)':
a.cc:10:46: error: reference to 'end' is ambiguous
   10 |         a[++cnt].go=v;a[cnt].s=w;a[cnt].next=end[u];end[u]=cnt;
      |                                              ^~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:166,
                 from a.cc:1:
/usr/include/c++/14/valarray:1265:5: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)'
 1265 |     end(const valarray<_Tp>& __va) noexcept
      |     ^~~
/usr/include/c++/14/valarray:1249:5: note:                 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)'
 1249 |     end(valarray<_Tp>& __va) noexcept
      |     ^~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52:
/usr/include/c++/14/bits/range_access.h:106:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])'
  106 |     end(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:85:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)'
   85 |     end(const _Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/bits/range_access.h:74:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)'
   74 |     end(_Container& __cont) -> decltype(__cont.end())
      |     ^~~
In file included from /usr/include/c++/14/bits/algorithmfwd.h:39,
                 from /usr/include/c++/14/bits/stl_algo.h:59,
                 from /usr/include/c++/14/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51:
/usr/include/c++/14/initializer_list:99:5: note:                 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:6:20: note:                 'int end [1100]'
    6 | int n,aa[1000],cnt,end[1100],f[1100],q[1100],s,t,id[1100],idd[1100];
      |                    ^~~
a.cc:10:53: error: reference to 'end' is ambiguous
   10 |         a[++cnt].go=v;a[cnt].s=w;a[cnt].next=end[u];end[u]=cnt;
      |                                                     ^~~
/usr/include/c++/14/valarray:1265:5: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)'
 1265 |     end(const valarray<_Tp>& __va) noexcept
      |     ^~~
/usr/include/c++/14/valarray:1249:5: note:                 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)'
 1249 |     end(valarray<_Tp>& __va) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:106:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])'
  106 |     end(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:85:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)'
   85 |     end(const _Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/bits/range_access.h:74:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)'
   74 |     end(_Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/initializer_list:99:5: note:                 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:6:20: note:                 'int end [1100]'
    6 | int n,aa[1000],cnt,end[1100],f[1100],q[1100],s,t,id[1100],idd[1100];
      |                    ^~~
a.cc:11:46: error: reference to 'end' is ambiguous
   11 |         a[++cnt].go=u;a[cnt].s=0;a[cnt].next=end[v];end[v]=cnt;
      |                                              ^~~
/usr/include/c++/14/valarray:1265:5: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)'
 1265 |     end(const valarray<_Tp>& __va) noexcept
      |     ^~~
/usr/include/c++/14/valarray:1249:5: note:                 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)'
 1249 |     end(valarray<_Tp>& __va) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:106:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])'
  106 |     end(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:85:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)'
   85 |     end(const _Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/bits/range_access.h:74:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)'
   74 |     end(_Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/initializer_list:99:5: note:                 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:6:20: note:                 'int end [1100]'
    6 | int n,aa[1000],cnt,end[1100],f[1100],q[1100],s,t,id[1100],idd[1100];
      |                    ^~~
a.cc:11:53: error: reference to 'end' is ambiguous
   11 |         a[++cnt].go=u;a[cnt].s=0;a[cnt].next=end[v];end[v]=cnt;
      |                                                     ^~~
/usr/include/c++/14/valarray:1265:5: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)'
 1265 |     end(const valarray<_Tp>& __va) noexcept
      |     ^~~
/usr/include/c++/14/valarray:1249:5: note:                 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)'
 1249 |     end(valarray<_Tp>& __va) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:106:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])'
  106 |     end(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:85:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)'
   85 |     end(const _Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/bits/range_access.h:74:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)'
   74 |     end(_Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/initializer_list:99:5: note:                 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:6:20: note:                 'int end [1100]'
    6 | int n,aa[1000],cnt,end[1100],f[1100],q[1100],s,t,id[1100],idd[1100];
      |                    ^~~
a.cc: In function 'bool bfs()':
a.cc:18:28: error: reference to 'end' is ambiguous
   18 |                 for (int i=end[now];i;i=a[i].next){
      |                            ^~~
/usr/include/c++/14/valarray:1265:5: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)'
 1265 |     end(const valarray<_Tp>& __va) noexcept
      |     ^~~
/usr/include/c++/14/valarray:1249:5: note:                 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)'
 1249 |     end(valarray<_Tp>& __va) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:106:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])'
  106 |     end(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:85:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)'
   85 |     end(const _Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/bits/range_access.h:74:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)'
   74 |     end(_Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/initializer_list:99:5: note:                 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:6:20: note:                 'int end [1100]'
    6 | int n,aa[1000],cnt,end[1100],f[1100],q[1100],s,t,id[1100],idd[1100];
      |                    ^~~
a.cc: In function 'long long int dinic(int, long long int)':
a.cc:29:20: error: reference to 'end' is ambiguous
   29 |         for (int i=end[sta];i&&os;i=a[i].next){
      |                    ^~~
/usr/include/c++/14/valarray:1265:5: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)'
 1265 |     end(const valarray<_Tp>& __va) noexcept
      |     ^~~
/usr/include/c++/14/valarray:1249:5: note:                 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)'
 1249 |     end(valarray<_Tp>& __va) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:106:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])'
  106 |     end(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:85:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)'
   85 |     end(const _Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/bits/range_access.h:74:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)'
   74 |     end(_Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/initializer_list:99:5: note:                 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:6:20: note:                 'int end [1100]'
    6 | int n,aa[1000],cnt,end[1100],f[1100],q[1100],s,t,id[1100],idd[1100];
      |                    ^~~