stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;



typedef long long ll;

const ll maxn = 100010;

ll n,q,top,tn;

ll a[maxn],S[maxn],tong[maxn],ci[maxn],sum[maxn];

vector <pair<ll,ll> >V[maxn];



ll find(ll x)

{

    ll l = 1,r = top,res = 1;

    while (l <= r)

    {

        ll mid = (l + r) >> 1;

        if (S[mid] <= x)

        {

            res = mid;

            l = mid + 1;

        }

        else

            r = mid - 1;

    }

    return res;

}



int main()

{

    scanf("%lld%lld",&n,&q);

    tn = n;

    for (ll i = 1; i <= q; i++)

        scanf("%lld",&a[i]);

    S[++top] = n;

    for (ll i = 1; i <= q; i++)

    {

        while (top && S[top] >= a[i])

            top--;

        S[++top] = a[i];

    }

    n = S[1];

    V[1].push_back(make_pair(-n,1));

    for (ll i = 2; i <= top; i++)

    {

        ll x = S[i];

        ll cur = i - 1;

        while (x > n)

        {

            ll temp = x / S[cur];

            V[i].push_back(make_pair(cur,temp));

            x %= S[cur];

            cur = find(x);

        }

        if (x > 0 && x <= n)

            V[i].push_back(make_pair(-x,1));

    }

    ci[top] = 1;

    for (ll i = top; i >= 1; i--)

        for (ll j = 0; j < V[i].size(); j++)

        {

            ll u = V[i][j].first,v = V[i][j].second;

            if (u < 0)

                tong[-u] += v * ci[i];

            else

                ci[u] += v * ci[i];

        }

    for (ll i = 1; i <= n; i++)

        if (tong[i])

        {

            sum[1] += tong[i];

            sum[i + 1] -= tong[i];

        }

    for (ll i = 1; i <= n; i++)

        sum[i] += sum[i - 1];

    for (ll i = 1; i <= n; i++)

        printf("%lld\n",sum[i]);

    for (ll i = n + 1; i <= tn; i++)

        puts("0");



    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 3.559443386275837x):
#include <bits/stdc++.h>

#define int long long

using namespace std;

const int N = 100010;

int q,n,len[N],val[N],ans[N],m;

void doit(int x,int v) {

//	printf("X %lld %lld\n", x, v);

	if (!x) return;

	int t = upper_bound(len+1,len+m+1,x) - len - 1;

//	printf("TT %lld\n", t);

	if (t == 0) ans[1] += v, ans[x+1] -= v;

	else {

		val[t] += (x / len[t]) * v;

		doit(x % len[t],v);

	}

}

signed main() {

	int x;

	scanf("%lld%lld",&n,&q);

	len[++m] = n;

	for (int i = 1 ; i <= q ; ++ i) {

		scanf("%lld",&x);

		while (m && len[m] >= x) -- m;

		len[++m] = x;

	}

	val[m] = 1;

	for (int i = m ; i >= 2 ; -- i) {

		val[i-1] += val[i] * (len[i] / len[i-1]);

//		printf("	%lld %lld %lld\n", len[i] % len[i - 1], val[i], i);

		doit(len[i] % len[i-1],val[i]);

	}

//	for (int i = 1; i <= m; ++i) printf("%lld\n", val[i]);

	ans[1] += val[1];

	ans[len[1]+1] -= val[1];

	for (int i = 2 ; i <= n ; ++ i)

		ans[i] += ans[i-1];

	for (int i = 1 ; i <= n ; ++ i)

		printf("%lld\n",ans[i]);

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define int long long

using namespace std;

const int N = 100010;

int q,n,len[N],val[N],ans[N],m;

void doit(int x,int v) {

//	printf("X %lld %lld\n", x, v);

	if (!x) return;

	int t = upper_bound(len+1,len+m+1,x) - len - 1;

//	printf("TT %lld\n", t);

	if (t == 0) ans[1] += v, ans[x+1] -= v;

	else {

		val[t] += (x / len[t]) * v;

		doit(x % len[t],v);

	}

}

signed main() {

	int x;

	scanf("%lld%lld",&n,&q);

	len[++m] = n;

	for (int i = 1 ; i <= q ; ++ i) {

		scanf("%lld",&x);

		while (m && len[m] >= x) -- m;

		len[++m] = x;

	}

	val[m] = 1;

	for (int i = m ; i >= 2 ; -- i) {

		val[i-1] += val[i] * (len[i] / len[i-1]);

//		printf("	%lld %lld %lld\n", len[i] % len[i - 1], val[i], i);

		doit(len[i] % len[i-1],val[i]);

	}

//	for (int i = 1; i <= m; ++i) printf("%lld\n", val[i]);

	ans[1] += val[1];

	ans[len[1]+1] -= val[1];

	for (int i = 2 ; i <= n ; ++ i)

		ans[i] += ans[i-1];

	for (int i = 1 ; i <= n ; ++ i)

		printf("%lld\n",ans[i]);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.182371064764728x):
#include <cstdio>

#include <cstring>

#include <algorithm>

using namespace std;

#define int long long

#define maxn (100010)

int n, m, top, s[maxn], cnt[maxn], sum[maxn];



inline int read() {

	int x = 0, f = 1;

	char ch = getchar();

	while (ch < '0' || ch > '9')

		ch == '-' ? f = -1, ch = getchar() : ch = getchar();

	while (ch >= '0' && ch <= '9')

		x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();

	return x * f;

}



void sol(int x, int del) {

//	printf("X %lld %lld\n", x, del);

	if (!x) return;

	int pos = upper_bound(s + 1, s + top + 1, x) - s - 1; // 找到比他大的，然后-1 

//	printf("POS %lld\n", pos);

	if (!pos) sum[1] += del, sum[x + 1] -= del;

	else cnt[pos] += (x / s[pos]) * del, sol(x % s[pos], del);

}



signed main() {

	n = read(), m = read();

	s[++top] = n;

	int x;

	for (int i = 1; i <= m; ++i) {

		x = read();

		while (top && s[top] >= x) --top;

		s[++top] = x;

	}

	cnt[top] = 1;

	for (int i = top; i >= 2; --i) {

		cnt[i - 1] += (s[i] / s[i - 1]) * cnt[i];

//		printf("	%lld %lld %lld\n", s[i] % s[i - 1], cnt[i], i);

		sol(s[i] % s[i - 1], cnt[i]);

	}

//	for (int i = 1; i <= top; ++i) printf("%lld\n", cnt[i]);

	sum[1] += cnt[1], sum[s[1] + 1] -= cnt[1]; // s[1]为最长长度

	for (int i = 1; i <= n; ++i) sum[i] += sum[i - 1];

	for (int i = 1; i <= n; ++i) printf("%lld\n", sum[i]); 

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;



typedef long long ll;

const ll maxn = 100010;

ll n,q,top,tn;

ll a[maxn],S[maxn],tong[maxn],ci[maxn],sum[maxn];

vector <pair<ll,ll> >V[maxn];



ll find(ll x)

{

    ll l = 1,r = top,res = 1;

    while (l <= r)

    {

        ll mid = (l + r) >> 1;

        if (S[mid] <= x)

        {

            res = mid;

            l = mid + 1;

        }

        else

            r = mid - 1;

    }

    return res;

}



int main()

{

    scanf("%lld%lld",&n,&q);

    tn = n;

    for (ll i = 1; i <= q; i++)

        scanf("%lld",&a[i]);

    S[++top] = n;

    for (ll i = 1; i <= q; i++)

    {

        while (top && S[top] >= a[i])

            top--;

        S[++top] = a[i];

    }

    n = S[1];

    V[1].push_back(make_pair(-n,1));

    for (ll i = 2; i <= top; i++)

    {

        ll x = S[i];

        ll cur = i - 1;

        while (x > n)

        {

            ll temp = x / S[cur];

            V[i].push_back(make_pair(cur,temp));

            x %= S[cur];

            cur = find(x);

        }

        if (x > 0 && x <= n)

            V[i].push_back(make_pair(-x,1));

    }

    ci[top] = 1;

    for (ll i = top; i >= 1; i--)

        for (ll j = 0; j < V[i].size(); j++)

        {

            ll u = V[i][j].first,v = V[i][j].second;

            if (u < 0)

                tong[-u] += v * ci[i];

            else

                ci[u] += v * ci[i];

        }

    for (ll i = 1; i <= n; i++)

        if (tong[i])

        {

            sum[1] += tong[i];

            sum[i + 1] -= tong[i];

        }

    for (ll i = 1; i <= n; i++)

        sum[i] += sum[i - 1];

    for (ll i = 1; i <= n; i++)

        printf("%lld\n",sum[i]);

    for (ll i = n + 1; i <= tn; i++)

        puts("0");



    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 3.521003266503538x):
#include<bits/stdc++.h>

using namespace std;

#define N 100010

typedef long long ll;

ll n,m,a[N],f[N],r[N],tp;

void dfs(ll x,ll v){

	ll p=upper_bound(a+1,a+tp+1,x)-a-1;

	if(!p){

		r[1]+=v;

		r[x+1]-=v;

		return;

	}

	f[p]+=v*(x/a[p]);

	dfs(x%a[p],v);

}

int main(){

	cin>>n>>m;

	a[++tp]=n;

	for(int i=1;i<=m;i++){

		ll x;

		cin>>x;

		while(x<=a[tp]&&tp)tp--;

		a[++tp]=x;

	}

	f[tp]=1;

	for(int i=tp-1;i;i--){

		f[i]+=f[i+1]*(a[i+1]/a[i]);

		dfs(a[i+1]%a[i],f[i+1]);

	}

	r[1]+=f[1];

	r[a[1]+1]-=f[1];

	for(int i=1;i<=n;i++)

		r[i]+=r[i-1];

	for(int i=1;i<=n;i++)

		cout<<r[i]<<'\n';

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;



typedef long long ll;

const ll maxn = 100010;

ll n,q,top,tn;

ll a[maxn],S[maxn],tong[maxn],ci[maxn],sum[maxn];

vector <pair<ll,ll> >V[maxn];



ll find(ll x)

{

    ll l = 1,r = top,res = 1;

    while (l <= r)

    {

        ll mid = (l + r) >> 1;

        if (S[mid] <= x)

        {

            res = mid;

            l = mid + 1;

        }

        else

            r = mid - 1;

    }

    return res;

}



int main()

{

    scanf("%lld%lld",&n,&q);

    tn = n;

    for (ll i = 1; i <= q; i++)

        scanf("%lld",&a[i]);

    S[++top] = n;

    for (ll i = 1; i <= q; i++)

    {

        while (top && S[top] >= a[i])

            top--;

        S[++top] = a[i];

    }

    n = S[1];

    V[1].push_back(make_pair(-n,1));

    for (ll i = 2; i <= top; i++)

    {

        ll x = S[i];

        ll cur = i - 1;

        while (x > n)

        {

            ll temp = x / S[cur];

            V[i].push_back(make_pair(cur,temp));

            x %= S[cur];

            cur = find(x);

        }

        if (x > 0 && x <= n)

            V[i].push_back(make_pair(-x,1));

    }

    ci[top] = 1;

    for (ll i = top; i >= 1; i--)

        for (ll j = 0; j < V[i].size(); j++)

        {

            ll u = V[i][j].first,v = V[i][j].second;

            if (u < 0)

                tong[-u] += v * ci[i];

            else

                ci[u] += v * ci[i];

        }

    for (ll i = 1; i <= n; i++)

        if (tong[i])

        {

            sum[1] += tong[i];

            sum[i + 1] -= tong[i];

        }

    for (ll i = 1; i <= n; i++)

        sum[i] += sum[i - 1];

    for (ll i = 1; i <= n; i++)

        printf("%lld\n",sum[i]);

    for (ll i = n + 1; i <= tn; i++)

        puts("0");



    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 3.5175141035886797x):
#include <iostream>

#include <stack>

#include <vector>

#include <cmath>

#include <algorithm>

#include <cstdio>

using namespace std; 

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

#define ll long long

#define rep(i,a,b) for(int i=a;i<=b;i++)

#define rep2(i,a,b) for(int i=a;i>=b;i--)

#define pb push_back

ll a[100005];

ll t[100005];

ll ans[100005];

ll g[100005];

int n,q;

int tot;

void dfs(ll cnt,ll x,ll tim)

{

//	cout<<cnt<<" "<<x<<" "<<tim<<endl;

	if(x<=a[1])

	{

		g[x]+=tim;

		return;

	}

	if(a[cnt-1])

	{

	t[cnt-1]+=tim*(x/a[cnt-1]);

	x%=a[cnt-1];

	}

	cnt=upper_bound(a+1,a+tot+cnt,x)-a;

	cnt++;

//	cout<<cnt<<endl;

	if(x&&cnt>1)dfs(cnt-1,x,tim);

}

int main(int argc, char** argv) {

	

	cin>>n>>q;

	tot=1;

	a[1]=n;

	rep(i,1,q)

	{

		ll x;

		scanf("%lld",&x);

		while(tot&&x<=a[tot])

		{

			tot--;

		}

		a[++tot]=x;

	}

	t[tot]=1;

	rep2(i,tot,1)

	{

		dfs(i,a[i],t[i]);

	}

	rep2(i,n-1,1)

	{

		g[i]+=g[i+1];

	}

	rep(i,1,n)

	printf("%lld\n",g[i]);

	return 0;

}
// Slower C++ solution:
#include <cstdio>

#include <queue>

typedef long long LL;

typedef std::pair<LL,LL> P;

std::priority_queue<P> Q;

const int N=100005;

LL a[N],cnt[N],ans[N];

void add(int i,LL x,LL y){

	cnt[i]+=x/a[i]*y;

	if (x%a[i]) Q.push(P(x%a[i],y));

}

int main(){

	int n,m,q;

	scanf("%d%d\n",&n,&q);

	a[m=1]=n;

	for (int i=1;i<=q;i++){

		long long x;

		scanf("%lld",&x);

		for (;m && x<=a[m];m--);

		a[++m]=x;

	}

	cnt[m]=1;

	for (int i=m-1;i>=1;i--){

		for (;!Q.empty() && Q.top().first>=a[i];Q.pop()){

			P p=Q.top();

			add(i,p.first,p.second);

		}

		add(i,a[i+1],cnt[i+1]);

	}

	ans[a[1]]+=cnt[1];

	for (;!Q.empty();Q.pop())

		ans[Q.top().first]+=Q.top().second;

	for (int i=a[1];i;i--) ans[i]+=ans[i+1];

	for (int i=1;i<=n;i++) printf("%lld\n",ans[i]);

}

// Faster C++ solution for the same problem (measured speedup: 4.789419415373538x):
#include <algorithm>

#include <cstdio>

typedef long long LL;

const int N=100005;

LL a[N],cnt[N],ans[N];

void add(int i,LL x,LL y){

	if (x<=a[1]){

		ans[x]+=y;

		return;

	}

	cnt[i]+=x/a[i]*y;x%=a[i];

	add(std::lower_bound(a+1,a+i,x)-a-1,x,y);

}

int main(){

	int n,m,q;

	scanf("%d%d\n",&n,&q);

	a[m=1]=n;

	for (int i=1;i<=q;i++){

		long long x;

		scanf("%lld",&x);

		for (;m && x<=a[m];m--);

		a[++m]=x;

	}

	cnt[m]=1;

	for (int i=m;i>=1;i--) add(i-1,a[i],cnt[i]);

	for (int i=a[1];i;i--) ans[i]+=ans[i+1];

	for (int i=1;i<=n;i++) printf("%lld\n",ans[i]);

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

using ll = long long;



vector<ll> a(200000);



int main(void){

    ll n, k;

    cin >> n >> k;

    rep(i, n) cin >> a[i];

    ll l = 1, h = *max_element(a.begin(), a.begin() + n);

    while(l < h){

        ll mid = (l + h) / 2, cnt = 0;

        rep(i, n){

            cnt += a[i] / mid;

            if(a[i] % mid == 0) --cnt;

        }

        if(cnt <= k) h = mid;

        else l = mid + 1;

    }

    cout << h << endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 2.608639167342798x):
#include<bits/stdc++.h>

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

using ll = long long;



int main(void){

    int n, k;

    cin >> n >> k;

    vector<int> a(n);

    rep(i, n) cin >> a[i];

    int l = 1, h = *max_element(a.begin(), a.end());

    while(l < h){

        int mid = (l + h) / 2, cnt = 0;

        rep(i, n){

            cnt += a[i] / mid;

            if(a[i] % mid == 0) --cnt;

        }

        if(cnt <= k) h = mid;

        else l = mid + 1;

    }

    cout << h << endl;

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



int main() {

  ios::sync_with_stdio(0);

  cin.tie(0), cout.tie(0);



  int N;

  cin >> N;



  vector<int> A(N + 1);

  for (int i = 1; i <= N; i++) {

    cin >> A[i];

  }



  long long ans = 0;

  vector<int> AA = A;



  auto Eval = [&](const vector<int> &order) {

    long long cost = 0;

    A = AA;

    for (auto i : order) {

      if (i == 0) continue;

      long long cur = 0;

      for (int j = i; j <= N; j += i) {

        cur += A[j];

      }

      if (cur < 0) {

        for (int j = i; j <= N; j += i) {

          A[j] = 0;

        }

      }

    }

    for (int i = 1; i <= N; i++) {

      cost += A[i];

    }

    return cost;

  };



  vector<int> order(N + 1);

  iota(begin(order), end(order), 0);

  ans = max(ans, Eval(order));

  reverse(begin(order), end(order));

  ans = max(ans, Eval(order));

  

  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

  for (int rep = 0; rep < 10000; rep++) {

    shuffle(begin(order), end(order), rnd);

    ans = max(ans, Eval(order));

  }



  cout << ans << "\n";

  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 2.0798697256561907x):
#include<bits/stdc++.h>

using namespace std;

#define endl "\n"

#define fi first

#define se second

#define pb push_back

#define mp make_pair

typedef long long ll;

typedef vector<ll> vi;

typedef pair<ll,ll> ii;

typedef vector<ii> vii;

const double PI = acos(-1);

const ll MOD = 1e9+7;

const ll MAXN = 2 * 1e3;



vi jalan[MAXN];

ll cap[MAXN][MAXN], val[MAXN], par[MAXN];

ll s, t, f, n, m;

ll res[MAXN][MAXN];



bool bfs(ll skrg) {

	bool vis[MAXN];

	memset(vis, 0, sizeof(vis));



	queue<ll> q;

	q.push(skrg);

	vis[skrg] = 1;

	par[skrg] = -1;



	while (!q.empty()) {

		ll cur = q.front();

		q.pop();



		for (ll i = 0; i < jalan[cur].size(); i++) {

			ll ttg = jalan[cur][i];

			if (!vis[ttg] && res[cur][ttg] > 0) {

				q.push(ttg);

				par[ttg] = cur;

				vis[ttg] = 1;

			}

		}

	}



	return vis[t];

}



int main(){

	cin >> n;

	s = 0; t = n + 1;

	ll tot = 0;

	for (ll i = 1; i <= n; i++) {

		ll x;

		cin >> x;



		if (x > 0) {

			jalan[i].pb(t);

			jalan[t].pb(i);

			cap[i][t] = x;

			tot += x;

		}

		else {

			jalan[s].pb(i);

			jalan[i].pb(s);

			cap[s][i] = -1 * x;



		}

	}



	for (ll i = 1; i <= n; i++) {

		for (ll j = 2*i; j <= n; j+=i) {

			jalan[i].pb(j);

			jalan[j].pb(i);

			cap[i][j] = INT_MAX;

		}

	}	





	for (ll i = 0; i <= n + 1; i++) {

		for (ll j = 0; j <= n + 1; j++) {

			res[i][j] = cap[i][j];

		}

	}

	

	ll mf = 0;



	while (bfs(s)) {

		ll p = INT_MAX;

		for (ll i = t; i != s; i = par[i]) {

			ll j = par[i];

			p = min(p, res[j][i]);

		}

		for (ll i = t; i != s; i = par[i]) {

			ll j = par[i];

			res[j][i] -= p;

			res[i][j] += p;

		}



		mf += p;

	}



	cout << tot - mf << endl;



}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



int main() {

  ios::sync_with_stdio(0);

  cin.tie(0), cout.tie(0);



  int N;

  cin >> N;



  vector<int> A(N + 1);

  for (int i = 1; i <= N; i++) {

    cin >> A[i];

  }



  long long ans = 0;

  vector<int> AA = A;



  auto Eval = [&](const vector<int> &order) {

    long long cost = 0;

    A = AA;

    for (auto i : order) {

      if (i == 0) continue;

      long long cur = 0;

      for (int j = i; j <= N; j += i) {

        cur += A[j];

      }

      if (cur < 0) {

        for (int j = i; j <= N; j += i) {

          A[j] = 0;

        }

      }

    }

    for (int i = 1; i <= N; i++) {

      cost += A[i];

    }

    return cost;

  };



  vector<int> order(N + 1);

  iota(begin(order), end(order), 0);

  ans = max(ans, Eval(order));

  reverse(begin(order), end(order));

  ans = max(ans, Eval(order));

  

  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

  for (int rep = 0; rep < 10000; rep++) {

    shuffle(begin(order), end(order), rnd);

    ans = max(ans, Eval(order));

  }



  cout << ans << "\n";

  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 2.1918555566248465x):
#include<bits/stdc++.h>

using namespace std;

#define ll long long

ll cap[105][105]; int par[105];

vector<int>adj[105];

const ll inf=1e12;

ll bfs(){

	memset(par, -1, sizeof(par));

	par[0]=-2;

	queue<pair<int, ll> >q;

	q.push({0, inf});

	for(;!q.empty();q.pop()){

		int nw=q.front().first; ll flow=q.front().second;

	//	cout<<nw<<" "<<flow<<" "<<par[nw]<<endl;

		for(int nx:adj[nw]) if(par[nx]==-1 && cap[nw][nx]>0){

			par[nx]=nw;

			ll nflw=min(flow, cap[nw][nx]);

		//	for(int i=1; i<=6; i++) cout<<par[i]<<" "; cout<<endl;

			if(nx==101) return nflw;

			q.push({nx, nflw});

		}

	}

	return 0;

}

ll maxflow(){

	ll flow=0, nflw;

	for(nflw=bfs();nflw;nflw=bfs()){

		flow+=nflw;

		int nw=101;

		while(nw!=0){

			int bf=par[nw];

			cap[bf][nw]-=nflw;

			cap[nw][bf]+=nflw;

			nw=bf;

		//	cout<<nw<<" "<<par[nw]<<endl;

		}

	}

	return flow;

}

void addedge(int u, int v, ll cp){

	cap[u][v]=cp;

	adj[u].push_back(v);

	adj[v].push_back(u);

}

int n, a[105];

int main(){

	scanf("%d", &n);

	for(int i=1; i<=n; i++) scanf("%d", &a[i]);

	ll optimal=0ll;

	for(int i=1; i<=n; i++){

		if(a[i]>0){

			optimal+=a[i];

			addedge(i, 101, 1ll*a[i]);

		}else{

			addedge(0, i, -1ll*a[i]);

		}

		for(int j=2*i; j<=n; j+=i)

			addedge(i, j, inf);

	}

	/*for(int i=0; i<=101; i++) if(adj[i].size()){

		for(int j:adj[i]){

			if(cap[i][j]){

				printf("%d %d %lld\n", i, j, cap[i][j]);

			}

		}

	}*/

	ll mincut=maxflow();

	printf("%lld\n", optimal-mincut);

	return 0;

}//
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



int main() {

  ios::sync_with_stdio(0);

  cin.tie(0), cout.tie(0);



  int N;

  cin >> N;



  vector<int> A(N + 1);

  for (int i = 1; i <= N; i++) {

    cin >> A[i];

  }



  long long ans = 0;

  vector<int> AA = A;



  auto Eval = [&](const vector<int> &order) {

    long long cost = 0;

    A = AA;

    for (auto i : order) {

      if (i == 0) continue;

      long long cur = 0;

      for (int j = i; j <= N; j += i) {

        cur += A[j];

      }

      if (cur < 0) {

        for (int j = i; j <= N; j += i) {

          A[j] = 0;

        }

      }

    }

    for (int i = 1; i <= N; i++) {

      cost += A[i];

    }

    return cost;

  };



  vector<int> order(N + 1);

  iota(begin(order), end(order), 0);

  ans = max(ans, Eval(order));

  reverse(begin(order), end(order));

  ans = max(ans, Eval(order));

  

  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

  for (int rep = 0; rep < 10000; rep++) {

    shuffle(begin(order), end(order), rnd);

    ans = max(ans, Eval(order));

  }



  cout << ans << "\n";

  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 2.179745516574832x):
#include<bits/stdc++.h>

using namespace std;



typedef long long ll;

const ll MAXN =105;

const ll INF = 1e18;



ll n,sum, cap[MAXN][MAXN],p[MAXN];

vector<ll> adj[MAXN];

queue<pair<ll,ll>> q;



ll bfs(int s, int t){

    while(!q.empty())q.pop();

    

    p[0] = -2;

    q.push({0ll,INF});

    while(!q.empty()){

        ll cur = q.front().first;

        ll flow = q.front().second;

        q.pop();

        for (auto next : adj[cur]){

            if (p[next] == -1 && cap[cur][next] > 0){

                p[next] = cur;

                ll newflow = min(flow,cap[cur][next]);

                if(next == t)

                    return newflow;

                q.push({next,newflow});

            }

        }

    }

    return 0;

}



ll maxflow(int s, int t){

    ll ans = 0;

    

    while(1){

        memset(p,-1,sizeof(p));

        ll newflow = bfs(s,t);

		if(!newflow)break;

        ans += newflow;



		long long cur = t;

		while(cur != s){

			long long prev = p[cur];

			cap[prev][cur] -= newflow;

			cap[cur][prev] += newflow;

			cur = prev;

		}

	}

    return ans;

}



int main(){

    cin>>n;

    ll tmp;

	for(ll i =1;i<=n;i++){

        cin >> tmp;

		

		if(tmp>=0){

			adj[i].push_back(n+1);

			adj[n+1].push_back(i);

			cap[i][n+1]+=tmp;

			sum+=tmp;

		}

		if(tmp<0){

			adj[i].push_back(0);

			adj[0].push_back(i);

			cap[0][i]-=tmp;

		}

		for(int j = 2*i; j <= n;j += i){

			adj[i].push_back(j);

			adj[j].push_back(i);

			cap[i][j]= INF;

		}

	}



    cout << sum - maxflow(0,n+1) << "\n";

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



int main() {

  ios::sync_with_stdio(0);

  cin.tie(0), cout.tie(0);



  int N;

  cin >> N;



  vector<int> A(N + 1);

  for (int i = 1; i <= N; i++) {

    cin >> A[i];

  }



  long long ans = 0;

  vector<int> AA = A;



  auto Eval = [&](const vector<int> &order) {

    long long cost = 0;

    A = AA;

    for (auto i : order) {

      if (i == 0) continue;

      long long cur = 0;

      for (int j = i; j <= N; j += i) {

        cur += A[j];

      }

      if (cur < 0) {

        for (int j = i; j <= N; j += i) {

          A[j] = 0;

        }

      }

    }

    for (int i = 1; i <= N; i++) {

      cost += A[i];

    }

    return cost;

  };



  vector<int> order(N + 1);

  iota(begin(order), end(order), 0);

  ans = max(ans, Eval(order));

  reverse(begin(order), end(order));

  ans = max(ans, Eval(order));

  

  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

  for (int rep = 0; rep < 10000; rep++) {

    shuffle(begin(order), end(order), rnd);

    ans = max(ans, Eval(order));

  }



  cout << ans << "\n";

  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 2.18037746133703x):
#include<bits/stdc++.h>

using namespace std;

typedef long long LL;

const LL MAXN=105,INF=1e18;

LL bneck,adj[MAXN][MAXN],source,sink,ans,n,a[MAXN];

bool visited[MAXN],sudah;



void dfs(LL node,LL bottleneck){

	if(node==sink){

		ans-=bottleneck;

		sudah=true;

		bneck=bottleneck;

		return;

	}

	if(!visited[node]){

		visited[node]=true;

		for(LL i=1;i<=n+2;i++){

			if(adj[node][i]>0){

				dfs(i,min(adj[node][i],bottleneck));

				if(sudah){

					adj[node][i]-=bneck;

					adj[i][node]+=bneck;

					return;

				}

			}

		}

	}

}



int main(){

	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

	cin >> n;

	for(LL i=1;i<=n;i++){

		cin >> a[i];

		if(a[i]>0){

			ans+=a[i];

			adj[i][n+2]=a[i];

		}

		else adj[n+1][i]=-a[i];

	}

	for(LL i=1;i<=n;i++){

		for(LL j=i+i;j<=n;j+=i)adj[i][j]=INF;

	}

	source=n+1;sink=n+2;

	sudah=true;

	while(sudah){

		memset(visited,false,sizeof(visited));

		sudah=false;

		dfs(source,INF);

	}

	cout << ans << endl;

	return 0;

}