Language: C++

#ifdef LOCAL
    #define _GLIBCXX_DEBUG
    #define __clock__
#else
    #pragma GCC optimize("Ofast")
#endif
#include<bits/stdc++.h>
using namespace std;
// using ll = long long;
using ll = __bit128;
using ld = long double;
using VI = vector<ll>;
using VV = vector<VI>;
using VS = vector<string>;
using PII = pair<ll, ll>;

// tourist set
template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << '\n'; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
// tourist set end

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,b) FOR(i, 0, b)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<'\n'
#define p2(s, t) cout << (s) << " " << (t) << '\n'
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << '\n'
#define SZ(x) ((int)(x).size())
#define SORT(A) sort(ALL(A))
#define RSORT(A) sort(ALL(A), greater<ll>())
#define MP make_pair
#define p_yes() p("Yes")
#define p_no() p("No")

ll SUM(VI& V){
  return accumulate(ALL(V), 0LL);
}

ll MIN(VI& V){return *min_element(ALL(V));}
ll MAX(VI& V){return *max_element(ALL(V));}

void print_vector(VI& V){
  ll n = V.size();
  rep(i, n){
    if(i) cout << ' ';
    cout << V[i];
  }
  cout << endl;
}

ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

// long double
using ld = long double;
#define EPS (1e-14)
#define equals(a,b) (fabs((a)-(b)) < EPS)

void no(){p_no(); exit(0);}
void yes(){p_yes(); exit(0);}

const ll mod = 1e9 + 7;
const ll inf = 1e18;
const double PI = acos(-1);

map<ll,ll> mp;
ll N,A,B,C,D;
ll cost[10];
VI M = {5,3,2};

ll f(ll a){
  if(mp.count(a)) return mp[a];
  if(a==1) return D;
  if(a==0) return 0;

  VI V; // candidate

  if(a<=1e9){
    V.push_back(a*D);
  }

  if(a==2) V.push_back(2*D);
  if(a==3) V.push_back(3*D);
  if(a==5) V.push_back(5*D);

  for(ll m : M){
    ll c = cost[m];
    if(a%m==0){
      V.push_back(f(a/m) + c);
    }else{
      ll r = a%m;
      // upper
      ll add = m-r;
      ll right = a + add;
      V.push_back(f(right/m) + c + add*D);
      // lower
      ll left = a - r;
      V.push_back(f(left/m) + c + r*D);
    }
  }
  return mp[a] = MIN(V);
}

void solve(){
  cin>>N>>A>>B>>C>>D;
  debug(N,A,B,C,D);
  cost[2] = A;
  cost[3] = B;
  cost[5] = C;

  mp.clear();
  ll ans = f(N);
  p(ans);
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    // input
    ll N; 
    cin>>N;
    
    while(N--)solve();
    
    return 0;
}

Compiler output:
a.cc:10:12: error: '__bit128' does not name a type; did you mean '__int128'?
   10 | using ll = __bit128;
      |            ^~~~~~~~
      |            __int128
a.cc:12:19: error: 'll' was not declared in this scope; did you mean 'ld'?
   12 | using VI = vector<ll>;
      |                   ^~
      |                   ld
a.cc:12:21: error: template argument 1 is invalid
   12 | using VI = vector<ll>;
      |                     ^
a.cc:12:21: error: template argument 2 is invalid
a.cc:13:19: error: 'VI' was not declared in this scope
   13 | using VV = vector<VI>;
      |                   ^~
a.cc:13:21: error: template argument 1 is invalid
   13 | using VV = vector<VI>;
      |                     ^
a.cc:13:21: error: template argument 2 is invalid
a.cc:15:18: error: 'll' was not declared in this scope; did you mean 'ld'?
   15 | using PII = pair<ll, ll>;
      |                  ^~
      |                  ld
a.cc:15:22: error: 'll' was not declared in this scope; did you mean 'ld'?
   15 | using PII = pair<ll, ll>;
      |                      ^~
      |                      ld
a.cc:15:24: error: template argument 1 is invalid
   15 | using PII = pair<ll, ll>;
      |                        ^
a.cc:15:24: error: template argument 2 is invalid
a.cc:124:1: error: 'll' does not name a type; did you mean 'ld'?
  124 | ll SUM(VI& V){
      | ^~
      | ld
a.cc:128:1: error: 'll' does not name a type; did you mean 'ld'?
  128 | ll MIN(VI& V){return *min_element(ALL(V));}
      | ^~
      | ld
a.cc:129:1: error: 'll' does not name a type; did you mean 'ld'?
  129 | ll MAX(VI& V){return *max_element(ALL(V));}
      | ^~
      | ld
a.cc:131:6: error: variable or field 'print_vector' declared void
  131 | void print_vector(VI& V){
      |      ^~~~~~~~~~~~
a.cc:131:19: error: 'VI' was not declared in this scope; did you mean 'VS'?
  131 | void print_vector(VI& V){
      |                   ^~
      |                   VS
a.cc:131:23: error: 'V' was not declared in this scope; did you mean 'VS'?
  131 | void print_vector(VI& V){
      |                       ^
      |                       VS
a.cc:140:1: error: 'll' does not name a type; did you mean 'ld'?
  140 | ll gcd(ll a,ll b){
      | ^~
      | ld
a.cc:145:1: error: 'll' does not name a type; did you mean 'ld'?
  145 | ll lcm(ll a,ll b){
      | ^~
      | ld
a.cc:158:7: error: 'll' does not name a type; did you mean 'ld'?
  158 | const ll mod = 1e9 + 7;
      |       ^~
      |       ld
a.cc:159:7: error: 'll' does not name a type; did you mean 'ld'?
  159 | const ll inf = 1e18;
      |       ^~
      |       ld
a.cc:162:5: error: 'll' was not declared in this scope; did you mean 'ld'?
  162 | map<ll,ll> mp;
      |     ^~
      |     ld
a.cc:162:8: error: 'll' was not declared in this scope; did you mean 'ld'?
  162 | map<ll,ll> mp;
      |        ^~
      |        ld
a.cc:162:10: error: template argument 1 is invalid
  162 | map<ll,ll> mp;
      |          ^
a.cc:162:10: error: template argument 2 is invalid
a.cc:162:10: error: template argument 3 is invalid
a.cc:162:10: error: template argument 4 is invalid
a.cc:163:1: error: 'll' does not name a type; did you mean 'ld'?
  163 | ll N,A,B,C,D;
      | ^~
      | ld
a.cc:164:1: error: 'll' does not name a type; did you mean 'ld'?
  164 | ll cost[10];
      | ^~
      | ld
a.cc:165:1: error: 'VI' does not name a type; did you mean 'VS'?
  165 | VI M = {5,3,2};
      | ^~
      | VS
a.cc:167:1: error: 'll' does not name a type; did you mean 'ld'?
  167 | ll f(ll a){
      | ^~
      | ld
a.cc: In function 'void solve()':
a.cc:201:8: error: 'N' was not declared in this scope
  201 |   cin>>N>>A>>B>>C>>D;
      |        ^
a.cc:201:11: error: 'A' was not declared in this scope
  201 |   cin>>N>>A>>B>>C>>D;
      |           ^
a.cc:201:14: error: 'B' was not declared in this scope
  201 |   cin>>N>>A>>B>>C>>D;
      |              ^
a.cc:201:17: error: 'C' was not declared in this scope
  201 |   cin>>N>>A>>B>>C>>D;
      |                 ^
a.cc:201:20: error: 'D' was not declared in this scope
  201 |   cin>>N>>A>>B>>C>>D;
      |                    ^
a.cc:203:3: error: 'cost' was not declared in this scope; did you mean 'cosl'?
  203 |   cost[2] = A;
      |   ^~~~
      |   cosl
a.cc:207:6: error: request for member 'clear' in 'mp', which is of non-class type 'int'
  207 |   mp.clear();
      |      ^~~~~
a.cc:208:3: error: 'll' was not declared in this scope; did you mean 'ld'?
  208 |   ll ans = f(N);
      |   ^~
      |   ld
a.cc:209:5: error: 'ans' was not declared in this scope; did you mean 'abs'?
  209 |   p(ans);
      |     ^~~
a.cc:113:21: note: in definition of macro 'p'
  113 | #define p(s) cout<<(s)<<'\n'
      |                     ^
a.cc: In function 'int main()':
a.cc:218:5: error: 'll' was not declared in this scope; did you mean 'ld'?
  218 |     ll N;
      |     ^~
      |     ld
a.cc:219:10: error: 'N' was not declared in this scope
  219 |     cin>>N;
      |          ^