Language: C++

# include <bits/stdc++.h>

# define pb push_back
# define fr first
# define sc second
# define mk make_pair
# define int long long

using namespace std;

const int inf = 1e9 + 7;
const int N = 2002;

typedef long long ll;

int n, a[N], u[N], b[N], ans, sum;

main()
{
      cin >> n;

      for(int i = 1; i <= n; i ++)
            cin >> a[i], sum += a[i];

      ans = max(ans, sum);

      for(int i = n; i >= 2; i --)
      {
            int sum = 0, cur = 0;
            for(int j = 1; j <= n; j ++)
                  if(!u[i]) cur += a[i];
            for(int j = 1; j <= n; j ++)
                  b[j] = u[j];
            for(int j = i; j <= n; j += i)
                  b[j] = 1;
            for(int j = 1; j <= n; j ++)
                  if(!b[j]) sum += a[j];
            if(sum > cur)
            {
                  ans = sum;
                  for(int j = 1; j <= n; j ++)
                        u[j] = b[j];
            }
      }

      cout << ans << endl;
}
# include <bits/stdc++.h>

# define pb push_back
# define fr first
# define sc second
# define mk make_pair
# define int long long

using namespace std;

const int inf = 1e9 + 7;
const int N = 2002;

typedef long long ll;

int n, a[N], u[N], b[N], ans, sum;

main()
{
      cin >> n;

      for(int i = 1; i <= n; i ++)
            cin >> a[i], sum += a[i];

      ans = max(ans, sum);

      for(int i = n; i >= 2; i --)
      {
            int sum = 0, cur = 0;
            for(int j = 1; j <= n; j ++)
                  if(!u[i]) cur += a[i];
            for(int j = 1; j <= n; j ++)
                  b[j] = u[j];
            for(int j = i; j <= n; j += i)
                  b[j] = 1;
            for(int j = 1; j <= n; j ++)
                  if(!b[j]) sum += a[j];
            if(sum > cur)
            {
                  ans = sum;
                  for(int j = 1; j <= n; j ++)
                        u[j] = b[j];
            }
      }

      cout << ans << endl;
}


Compiler output:
a.cc:18:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   18 | main()
      | ^~~~
a.cc:58:11: error: redefinition of 'const long long int inf'
   58 | const int inf = 1e9 + 7;
      |           ^~~
a.cc:11:11: note: 'const long long int inf' previously defined here
   11 | const int inf = 1e9 + 7;
      |           ^~~
a.cc:59:11: error: redefinition of 'const long long int N'
   59 | const int N = 2002;
      |           ^
a.cc:12:11: note: 'const long long int N' previously defined here
   12 | const int N = 2002;
      |           ^
a.cc:63:5: error: redefinition of 'long long int n'
   63 | int n, a[N], u[N], b[N], ans, sum;
      |     ^
a.cc:16:5: note: 'long long int n' previously declared here
   16 | int n, a[N], u[N], b[N], ans, sum;
      |     ^
a.cc:63:8: error: redefinition of 'long long int a [2002]'
   63 | int n, a[N], u[N], b[N], ans, sum;
      |        ^
a.cc:16:8: note: 'long long int a [2002]' previously declared here
   16 | int n, a[N], u[N], b[N], ans, sum;
      |        ^
a.cc:63:14: error: redefinition of 'long long int u [2002]'
   63 | int n, a[N], u[N], b[N], ans, sum;
      |              ^
a.cc:16:14: note: 'long long int u [2002]' previously declared here
   16 | int n, a[N], u[N], b[N], ans, sum;
      |              ^
a.cc:63:20: error: redefinition of 'long long int b [2002]'
   63 | int n, a[N], u[N], b[N], ans, sum;
      |                    ^
a.cc:16:20: note: 'long long int b [2002]' previously declared here
   16 | int n, a[N], u[N], b[N], ans, sum;
      |                    ^
a.cc:63:26: error: redefinition of 'long long int ans'
   63 | int n, a[N], u[N], b[N], ans, sum;
      |                          ^~~
a.cc:16:26: note: 'long long int ans' previously declared here
   16 | int n, a[N], u[N], b[N], ans, sum;
      |                          ^~~
a.cc:63:31: error: redefinition of 'long long int sum'
   63 | int n, a[N], u[N], b[N], ans, sum;
      |                               ^~~
a.cc:16:31: note: 'long long int sum' previously declared here
   16 | int n, a[N], u[N], b[N], ans, sum;
      |                               ^~~
a.cc:65:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   65 | main()
      | ^~~~
a.cc:65:1: error: redefinition of 'int main()'
a.cc:18:1: note: 'int main()' previously defined here
   18 | main()
      | ^~~~