Language: C++

#include "bits/stdc++.h"
using namespace std;

int way;
long long int cost[102];

bitset<102> dv[102];
long long int C;

vector<int> gr[102];

bool pos[102];


inline void dfs(long long int idx, bitset<102> val) {
	if (idx == 22) {
		long long int ans = 0;
		for (int j = 1; j <= 21; j++) {
			if ((val&dv[j]) == 0LL) {
				ans += cost[j];
			}
		}
		for (int j = 22; j <= 50; j++) {
			if (j * 3 <= 100 && j % 2) {
				if (dv[j] & val)continue;
				long long int U = cost[j];
				if ((val&dv[j * 2]) == 0LL) {
					U += max(0LL, cost[j * 2]);
				}
				if ((val&dv[j * 3]) == 0LL) {
					U += max(0LL, cost[j * 3]);
				}
				if (U >= 0) {
					ans += cost[j];
				}
				else {
					val.set(j, 1);
					//val |= (1LL << (long long int)(j));
				}
				continue;
			}
			if (j * 3 <= 100) {
				int o1 = j;
				int o2 = j * 3 / 2;
				long long int www = 0;
				int id = -1;
				for (int k = 0; k < 4; k++) {
					auto val2 = val;
					if (k & 1) {
						val2.set(o1, 1);
						//val2 |= (1LL << (long long int)(o1));
					}
					if ((k >> 1) & 1) {
						//val2 |= (1LL << (long long int)(o2));
						val2.set(o2, 1);
					}
					long long int ad = 0;
					for (auto el : gr[j]) {
						if ((dv[el] & val2) == 0LL) {
							if (el >= 50) {
								ad += max(0LL, cost[el]);
							}
							else {
								ad += cost[el];
							}
						}
					}
					www = max(www, ad);
					if (www == ad) {
						id = k;
					}
				}
				if (id & 1) {
					val.set(o1, 1);
					//val |= (1LL << (long long int)(o1));
				}
				if ((id >> 1) & 1) {
					//val |= (1LL << (long long int)(o2));
					val.set(o2, 1);
				}
				for (auto el : gr[j]) {
					if ((dv[el] & val) == 0LL) {
						if (el >= 50) {

						}
						else {
							ans += cost[el];
						}
					}
				}
				continue;
			}
			if (pos[j] == false) {
				if ((val&dv[j]).any())continue;
				long long int nex = j * 2;
				long long int U = cost[j];
				if ((val&dv[nex]) == 0LL) {
					U += max(0LL, cost[nex]);
				}
				if (U >= 0) {
					ans += cost[j];
				}
				else {
					val |= (1LL << (long long int)(j));
				}
				continue;
			}
		}
		for (int j = 51; j <= 100; j++) {
			if ((val&dv[j]).any()) {
				continue;
			}
			ans += max(0LL, cost[j]);
		}
		C = max(C, ans);

		return;
	}
	bool ng = false;
	if ((val&dv[idx]).any()) {
		ng = true;
	}
	if (ng == false) {
		dfs(idx + 1, val);
	}
	val.set(idx, 1);
	dfs(idx + 1, val );
}

int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= 100; i++) {
		scanf("%lld", &cost[i]);
	}
	for (int i = 1; i <= 100; i++) {
		for (int j = 1; j <= i; j++) {
			if (i%j == 0) {
				dv[i].set(j, 1);// |= (1LL << (long long int)(j));
			}
		}
		if (i >= 27) {
			if (i * 3 <= 100) {
				gr[i].push_back(i);
				gr[i].push_back(i * 3);
				gr[i].push_back(i * 3 / 2);
				gr[i].push_back(i * 2);
				if ((i * 3) % 2 == 0)pos[i * 3 / 2] = true;
			}
		}
	}
	dfs(1, 0);
	printf("%lld\n", C);
	return 0;
}


Compiler output:
a.cc: In function 'void dfs(long long int, std::bitset<102>)':
a.cc:25:43: error: could not convert 'std::operator&<102>(dv[j], val)' from 'std::bitset<102>' to 'bool'
   25 |                                 if (dv[j] & val)continue;
      |                                     ~~~~~~^~~~~
      |                                           |
      |                                           std::bitset<102>