Language: C++

#include <iostream>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <string>
#include <algorithm>
#include <time.h>
#include <assert.h>

using namespace::std;

int ri()
{
        int x;
        scanf("%d", &x);

        return x;
}

void wi(int x)
{
        printf("%d\n", x);
}

bool ok(int x, int y, int N)
{
        int prev_x = x;
        int prev_y = y;

        for (int i = 2; ; i++)
        {
                int curr_x = i * x;
                int curr_y = i * y;

                if (curr_x > N)
                        break;

                if (curr_x <= prev_y)
                        return false;
        }

        return true;
}

int64_t get(int x, vector<int64_t> &A, vector<bool> &mark)
{       
        int64_t ans = 0;
        int y = x;
        
        while (y < A.size())
        {       
                if (!mark[y])
                        ans += A[y];
                
                y += x;
        }
        
        return ans;
}

int main()
{
        int N = ri();

        vector<int64_t> A(1 + N);
        int64_t sm = 0;

        for (int i = 1; i <= N; i++)
        {
                A[i] = ri();
                sm += A[i];
        }

        vector<bool> mark(1 + N, false);

        int64_t bd = 0;
        if (A[N] < 0)
        {
                bd += A[N];
                mark[N] = true;
        }

        int l = N;
        int r = -1;

        for (int r1 = 2; ; r1++)
        {
                r = l - 1;
                l = 1 + N/r1;

                if (l > r)
                        break;

                if (!ok(l, r, N))
                        break;

                for (int i = l; i <= r; i++)
                {       
                        int64_t x = get(i, A, mark);
                        if (x < 0)
                        {       
                                for (int j = i; j <= N; j += i)
                                        mark[j] = true;
                                
                                bd += x;
                        }
                }
        }
        
        // We need to brute force for the range from [1, r]
                
        int64_t bst = 0;
                
        if (r >= 1)
        {
        for (int i = 0; i < (1 << r); i++)
        {
                set<int> S;
                for (int j = 1; j <= r; j++)
                {
                        if (i & (1 << (j - 1)))
                        {
                                for (int k = j; k <= N; k += j)
                                        S.insert(k);
                        }
                }
        
                int64_t t = 0;
                for (set<int>::iterator it = S.begin(); it != S.end(); it++)
                {
                        if (!mark[*it])
                                t += A[*it];
                }
                if (t < bst)
                        bst = t;
        }
        }
                
        bd += bst;
        
        int64_t ans = sm - bd;
        printf("%lld\n", ans);
        
        return 0;
}       
~                                        

Compiler output:
a.cc:154:2: error: expected class-name at end of input
  154 | ~
      |  ^