Language: C++

#include <bits/stdc++.h>

using namespace std;

using int64 = long long;
const int64 INF = 1LL << 59;

unordered_map< int64, int > prime_factor(int64 n)
{
  unordered_map< int64, int > ret;
  for(int64 i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return (ret);
}

int Q;
pair< unordered_map< int64, int >, int > vv[300];

int64 rec(vector< pair< int, int > > &conv, vector< int > &candidate, int idx, bool flag)
{
  int64 ret = -INF;
  if(candidate.empty()) {
    return (ret);
  }
  if(flag) {
    ret = 0;
    for(auto &j : candidate) ret += vv[j].second;
  }
  if(idx < conv.size()) {
    if(conv[idx].first >= 17 && flag) {

      vector< int > used(Q, 0);
      int64 negative = -INF, positive = 0;
      bool negativeadd = false, positiveadd = false;
      int64 pre = 0;
      bool preadd = false;

      for(int i = idx; i < conv.size(); i++) {
        int64 beet = 0;
        bool f = false;
        for(auto &j : candidate) {
          if(vv[j].first.count(conv[i].first)) {
            beet += vv[j].second;
            assert(used[j] == 0);
            used[j] = true;
            f = true;
          }
        }
        if(f) {
          if(beet <= 0) {
            negative = max(negative, beet);
            negativeadd = true;
          } else {
            positive += beet;
            positiveadd = true;
          }
        }
      }

      for(auto &j : candidate) {
        if(!used[j]) {
          preadd = true;
          pre += vv[j].second;
        }
      }

      if(preadd) {
        ret = max(ret, pre + positive);
      } else if(positiveadd) {
        ret = max(ret, positive);
      } else if(negativeadd) {
        ret = max(ret, negative);
      }

    } else {
      set< vector< int > > used;
      for(int i = 0; i <= conv[idx].second + 1; i++) {
        vector< int > nt;
        for(int j : candidate) {
          if(vv[j].first.count(conv[idx].first)) {
            if(vv[j].first[conv[idx].first] > i) continue;
          }
          nt.emplace_back(j);
        }
        if(used.count(nt)) continue;
        used.emplace(nt);
        ret = max(ret, rec(conv, nt, idx + 1, flag | (i > 0)));
      }
    }
  }
  return (ret);
}


int main()
{
  cin >> Q;
  map< int, int > mx;
  for(int i = 0; i < Q; i++) {
    int m, x;
    cin >> m >> x;
    auto latte = prime_factor(m);
    for(auto &p : latte) {
      mx[p.first] = max(mx[p.first], p.second);
    }
    vv[i] = {latte, x};
  }
  vector< pair< int, int > > convert(begin(mx), end(mx));
  vector< int > candidate(Q);
  iota(begin(candidate), end(candidate), 0);
  cout << max(0, rec(convert, candidate, 0, false)) << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:116:14: error: no matching function for call to 'max(int, int64)'
  116 |   cout << max(0, rec(convert, candidate, 0, false)) << endl;
      |           ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:116:14: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'int64' {aka 'long long int'})
  116 |   cout << max(0, rec(convert, candidate, 0, false)) << endl;
      |           ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:116:14: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  116 |   cout << max(0, rec(convert, candidate, 0, false)) << endl;
      |           ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~