Language: C++


 #include <cstdio>
 #include <cstdlib>
 #include <iostream>
 #include <fstream>
 #include <cstdio>
 #include <cstdlib>
 #include <iostream>
 #include <fstream>
 #include <sstream>
 #include <set>
 #include <map>
 #include <vector>
 #include <list>
 #include <algorithm>
 #include <cstring>
 #include <cmath>
 #include <string>
 #include <queue>
 #include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
 #include <cassert>
 #include <iomanip>        //do setprecision
 #include <ctime>
 #include <complex>
 using namespace std;

 #define FOR(i,b,e) for(int i=(b);i<(e);++i)
 #define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
 #define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
 #define REP(x, n) for(int x = 0; x < (n); ++x)

 #define ST first
 #define ND second
 #define PB push_back
 #define PF push_front
 #define MP make_pair
 #define LL long long
 #define ULL unsigned LL
 #define LD long double
 #define pii pair<int,int>
 #define pll pair<LL,LL>

 const double pi = 3.14159265358979323846264;
 const int mod=1000000007;

 // dinic
 struct max_flow {//V:頂点数 O(EV^2)だが実際はより高速
     struct edge { LL to, cap, rev; };
     int V;
     vector<vector<edge>> G;
     vector<int> itr, level;

     max_flow(int V) : V(V) { G.assign(V,vector<edge>()); }

     void add_edge(int from, int to, LL cap) {
         G[from].push_back((edge) {to, cap, (int) G[to].size()});
         G[to].push_back((edge) {from, 0, (int) G[from].size()-1});
     }
 //sからの最短距離をbfs計算
     void bfs(LL s) {
         level.assign(V,-1);
         queue<int> q;
         level[s] = 0; q.push(s);
         while (!q.empty()) {
             int v = q.front(); q.pop();
             for(auto &e: G[v]){
                 if (e.cap > 0 and level[e.to] < 0) {
                     level[e.to] = level[v] + 1;
                     q.push(e.to);
                 }
             }
         }
     }
 //増加パスをdfsで探索
     LL dfs(int v, LL t, LL f) {
         if (v == t) return f;
         for (int& i = itr[v]; i < (int) G[v].size(); ++i) {
             edge& e = G[v][i];
             if (e.cap > 0 and level[v] < level[e.to]) {
                 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;
     }

     LL run(int s, int t) {//s to t
         LL ret = 0, f;
         while (bfs(s), level[t] >= 0) {
             itr.assign(V,0);
             while ((f = dfs(s, t, mod)) > 0) ret += f;//mod use as inf
         }
         return ret;
     }
 };


int main(){
	int n,a[111]={};
	cin>>n;
	max_flow mf(n+2);//0:破壊,n+1:残存
	LL mx=0;
	FORQ(i,1,n){
		cin>>a[i];
		if(a[i]>=0){
			mx+=a[i];
			mf.add_edge(0,i,a[i]);
		}else{
			mf.add_edge(i,n+1,-a[i]);
		}
		FORQ(j,2,n/i){
			int to=j*i;
			mf.add_edge(to,i,1LL*mod*1000000);
		}
	}
	cerr<<mx<<endl;
	cout<<mx-mf.run(0,n+1)<<endl;

	return 0;
}

 #include <sstream>
 #include <set>
 #include <map>
 #include <vector>
 #include <list>
 #include <algorithm>
 #include <cstring>
 #include <cmath>
 #include <string>
 #include <queue>
 #include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
 #include <cassert>
 #include <iomanip>        //do setprecision
 #include <ctime>
 #include <complex>
 using namespace std;

 #define FOR(i,b,e) for(int i=(b);i<(e);++i)
 #define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
 #define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
 #define REP(x, n) for(int x = 0; x < (n); ++x)

 #define ST first
 #define ND second
 #define PB push_back
 #define PF push_front
 #define MP make_pair
 #define LL long long
 #define ULL unsigned LL
 #define LD long double
 #define pii pair<int,int>
 #define pll pair<LL,LL>

 const double pi = 3.14159265358979323846264;
 const int mod=1000000007;

 // dinic
 struct max_flow {//V:頂点数 O(EV^2)だが実際はより高速
     struct edge { LL to, cap, rev; };
     int V;
     vector<vector<edge>> G;
     vector<int> itr, level;

     max_flow(int V) : V(V) { G.assign(V,vector<edge>()); }

     void add_edge(int from, int to, LL cap) {
         G[from].push_back((edge) {to, cap, (int) G[to].size()});
         G[to].push_back((edge) {from, 0, (int) G[from].size()-1});
     }
 //sからの最短距離をbfs計算
     void bfs(LL s) {
         level.assign(V,-1);
         queue<int> q;
         level[s] = 0; q.push(s);
         while (!q.empty()) {
             int v = q.front(); q.pop();
             for(auto &e: G[v]){
                 if (e.cap > 0 and level[e.to] < 0) {
                     level[e.to] = level[v] + 1;
                     q.push(e.to);
                 }
             }
         }
     }
 //増加パスをdfsで探索
     LL dfs(int v, LL t, LL f) {
         if (v == t) return f;
         for (int& i = itr[v]; i < (int) G[v].size(); ++i) {
             edge& e = G[v][i];
             if (e.cap > 0 and level[v] < level[e.to]) {
                 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;
     }

     LL run(int s, int t) {//s to t
         LL ret = 0, f;
         while (bfs(s), level[t] >= 0) {
             itr.assign(V,0);
             while ((f = dfs(s, t, mod)) > 0) ret += f;//mod use as inf
         }
         return ret;
     }
 };


int main(){
	int n,a[111]={};
	cin>>n;
	max_flow mf(n+2);//0:破壊,n+1:残存
	LL mx=0;
	FORQ(i,1,n){
		cin>>a[i];
		if(a[i]>=0){
			mx+=a[i];
			mf.add_edge(0,i,a[i]);
		}else{
			mf.add_edge(i,n+1,-a[i]);
		}
		FORQ(j,2,n/i){
			int to=j*i;
			mf.add_edge(j,i,1LL*mod*1000000);
		}
	}
	cerr<<mx<<endl;
	cout<<mx-mf.run(0,n+1)<<endl;

	return 0;
}


Compiler output:
a.cc:159:15: error: redefinition of 'const double pi'
  159 |  const double pi = 3.14159265358979323846264;
      |               ^~
a.cc:43:15: note: 'const double pi' previously defined here
   43 |  const double pi = 3.14159265358979323846264;
      |               ^~
a.cc:160:12: error: redefinition of 'const int mod'
  160 |  const int mod=1000000007;
      |            ^~~
a.cc:44:12: note: 'const int mod' previously defined here
   44 |  const int mod=1000000007;
      |            ^~~
a.cc:163:9: error: redefinition of 'struct max_flow'
  163 |  struct max_flow {//V:頂点数 O(EV^2)だが実際はより高速
      |         ^~~~~~~~
a.cc:47:9: note: previous definition of 'struct max_flow'
   47 |  struct max_flow {//V:頂点数 O(EV^2)だが実際はより高速
      |         ^~~~~~~~
a.cc:218:5: error: redefinition of 'int main()'
  218 | int main(){
      |     ^~~~
a.cc:102:5: note: 'int main()' previously defined here
  102 | int main(){
      |     ^~~~