Language: C++

int main(){
  int t;
  cin>>t;
  ll n,a,b,c,d;
  ll ans=INF;
  ll u=INF;
  rep(i,t){
    
    cin>>n>>a>>b>>c>>d;
    
    ll ad,bd,cd;
    if(a%d==0) {
      ad=a/d;
      ad*=2;
    }
    else {
      ad=a/d+1;
      ad*=2;
      ad--;
    }
    
    if(b%d==0) {
      bd=b/d;
      bd*=3;
    }
    else{
      bd=b/d+1;
      bd*=3;
      bd--;
    }
    
    
    if(c%d==0) {
      cd=c/d;
      cd*=5;
    }
    else {
      cd=c/d+1;
      cd*=5;
      cd--;
    }
    
    
    
    u=min(u,ad);
    u=min(u,bd);
    u=min(u,cd);
  }
    
    //cout<<u<<endl;
    
    queue<P> q;
    q.push(P(n,0));
    
    while(!(q.empty())){
      P p=q.front();q.pop();
      if(p.fi<=u){
        ans=min(ans,p.se+d*p.fi);
        continue;
      }
      if((p.fi/5*4/c)>(p.fi/3*2/b)){
        if(p.fi%5==1){
        q.push(P((p.fi-1)/5,p.se+c+d));
      }
      if(p.fi%5==2){
        q.push(P((p.fi-2)/5,p.se+c+d+d));
      }
      if(p.fi%5==3){
        q.push(P((p.fi+2)/5,p.se+c+d+d));
      }
      if(p.fi%5==4){
        q.push(P((p.fi+1)/5,p.se+c+d));
      }
      if(p.fi%5==0){
        q.push(P(p.fi/5,p.se+c));
      }
      continue;
      }
      
      
      if((p.fi/3*2/b)>(p.fi/2*1/a)){
        if(p.fi%3==0){
        q.push(P(p.fi/3,p.se+b));
      }
        if(p.fi%3==1){
        q.push(P((p.fi-1)/3,p.se+b+d));
      }
      if(p.fi%3==2){
        q.push(P((p.fi+1)/3,p.se+b+d));
      }
        
        continue;
      }
        
        
        
        
        
      if(p.fi%2==0){
        q.push(P(p.fi/2,p.se+a));
      }
      if(p.fi%2==1){
        q.push(P((p.fi-1)/2,p.se+a+d));
      }
      if(p.fi%3==0){
        q.push(P(p.fi/3,p.se+b));
      }
      if(p.fi%5==0){
        q.push(P(p.fi/5,p.se+c));
      }
      if(p.fi%3==1){
        q.push(P((p.fi-1)/3,p.se+b+d));
      }
      if(p.fi%3==2){
        q.push(P((p.fi+1)/3,p.se+b+d));
      }
      if(p.fi%5==1){
        q.push(P((p.fi-1)/5,p.se+c+d));
      }
      if(p.fi%5==2){
        q.push(P((p.fi-2)/5,p.se+c+d+d));
      }
      if(p.fi%5==3){
        q.push(P((p.fi+2)/5,p.se+c+d+d));
      }
      if(p.fi%5==4){
        q.push(P((p.fi+1)/5,p.se+c+d));
      }
    }
    
    
    
    cout<<ans<<endl;
    
}
      
    
    
    



Compiler output:
a.cc: In function 'int main()':
a.cc:3:3: error: 'cin' was not declared in this scope
    3 |   cin>>t;
      |   ^~~
a.cc:4:3: error: 'll' was not declared in this scope
    4 |   ll n,a,b,c,d;
      |   ^~
a.cc:5:5: error: expected ';' before 'ans'
    5 |   ll ans=INF;
      |     ^~~~
      |     ;
a.cc:6:5: error: expected ';' before 'u'
    6 |   ll u=INF;
      |     ^~
      |     ;
a.cc:7:7: error: 'i' was not declared in this scope
    7 |   rep(i,t){
      |       ^
a.cc:7:3: error: 'rep' was not declared in this scope
    7 |   rep(i,t){
      |   ^~~
a.cc:52:5: error: 'queue' was not declared in this scope
   52 |     queue<P> q;
      |     ^~~~~
a.cc:52:11: error: 'P' was not declared in this scope
   52 |     queue<P> q;
      |           ^
a.cc:52:14: error: 'q' was not declared in this scope
   52 |     queue<P> q;
      |              ^
a.cc:53:14: error: 'n' was not declared in this scope
   53 |     q.push(P(n,0));
      |              ^
a.cc:56:8: error: expected ';' before 'p'
   56 |       P p=q.front();q.pop();
      |        ^~
      |        ;
a.cc:57:10: error: 'p' was not declared in this scope
   57 |       if(p.fi<=u){
      |          ^
a.cc:57:16: error: 'u' was not declared in this scope
   57 |       if(p.fi<=u){
      |                ^
a.cc:58:9: error: 'ans' was not declared in this scope
   58 |         ans=min(ans,p.se+d*p.fi);
      |         ^~~
a.cc:58:26: error: 'd' was not declared in this scope
   58 |         ans=min(ans,p.se+d*p.fi);
      |                          ^
a.cc:58:13: error: 'min' was not declared in this scope; did you mean 'main'?
   58 |         ans=min(ans,p.se+d*p.fi);
      |             ^~~
      |             main
a.cc:61:11: error: 'p' was not declared in this scope
   61 |       if((p.fi/5*4/c)>(p.fi/3*2/b)){
      |           ^
a.cc:61:20: error: 'c' was not declared in this scope
   61 |       if((p.fi/5*4/c)>(p.fi/3*2/b)){
      |                    ^
a.cc:61:33: error: 'b' was not declared in this scope
   61 |       if((p.fi/5*4/c)>(p.fi/3*2/b)){
      |                                 ^
a.cc:63:36: error: 'd' was not declared in this scope
   63 |         q.push(P((p.fi-1)/5,p.se+c+d));
      |                                    ^
a.cc:66:36: error: 'd' was not declared in this scope
   66 |         q.push(P((p.fi-2)/5,p.se+c+d+d));
      |                                    ^
a.cc:69:36: error: 'd' was not declared in this scope
   69 |         q.push(P((p.fi+2)/5,p.se+c+d+d));
      |                                    ^
a.cc:72:36: error: 'd' was not declared in this scope
   72 |         q.push(P((p.fi+1)/5,p.se+c+d));
      |                                    ^
a.cc:81:11: error: 'p' was not declared in this scope
   81 |       if((p.fi/3*2/b)>(p.fi/2*1/a)){
      |           ^
a.cc:81:20: error: 'b' was not declared in this scope
   81 |       if((p.fi/3*2/b)>(p.fi/2*1/a)){
      |                    ^
a.cc:81:33: error: 'a' was not declared in this scope
   81 |       if((p.fi/3*2/b)>(p.fi/2*1/a)){
      |                                 ^
a.cc:86:36: error: 'd' was not declared in this scope
   86 |         q.push(P((p.fi-1)/3,p.se+b+d));
      |                                    ^
a.cc:89:36: error: 'd' was not declared in this scope
   89 |         q.push(P((p.fi+1)/3,p.se+b+d));
      |                                    ^
a.cc:99:10: error: 'p' was not declared in this scope
   99 |       if(p.fi%2==0){
      |          ^
a.cc:100:30: error: 'a' was not declared in this scope
  100 |         q.push(P(p.fi/2,p.se+a));
      |                              ^
a.cc:102:10: error: 'p' was not declared in this scope
  102 |       if(p.fi%2==1){
      |          ^
a.cc:103:34: error: 'a' was not declared in this scope
  103 |         q.push(P((p.fi-1)/2,p.se+a+d));
      |                                  ^
a.cc:103:36: error: 'd' was not declared in this scope
  103 |         q.push(P((p.fi-1)/2,p.se+a+d));
      |                                    ^
a.cc:105:10: error: 'p' was not declared in this scope
  105 |       if(p.fi%3==0){
      |          ^
a.cc:106:30: error: 'b' was not declared in this scope
  106 |         q.push(P(p.fi/3,p.se+b));
      |                              ^
a.cc:108:10: error: 'p' was not declared in this scope
  108 |       if(p.fi%5==0){
      |          ^
a.cc:109:30: error: 'c' was not declared in this scope
  109 |         q.push(P(p.fi/5,p.se+c));
      |                              ^
a.cc:111:10: error: 'p' was not declared in this scope
  111 |       if(p.fi%3==1){
      |          ^
a.cc:112:34: error: 'b' was not declared in this scope
  112 |         q.push(P((p.fi-1)/3,p.se+b+d));
      |                                  ^
a.cc:112:36: error: 'd' was not declared in this scope
  112 |         q.push(P((p.fi-1)/3,p.se+b+d));
      |                                    ^
a.cc:114:10: error: 'p' was not declared in this scope
  114 |       if(p.fi%3==2){
      |          ^
a.cc:115:34: error: 'b' was not declared in this scope
  115 |         q.push(P((p.fi+1)/3,p.se+b+d));
      |                                  ^
a.cc:115:36: error: 'd' was not declared in this scope
  115 |         q.push(P((p.fi+1)/3,p.se+b+d));
      |                                    ^
a.cc:117:10: error: 'p' was not declared in this scope
  117 |       if(p.fi%5==1){
      |          ^
a.cc:118:34: error: 'c' was not declared in this scope
  118 |         q.push(P((p.fi-1)/5,p.se+c+d));
      |                                  ^
a.cc:118:36: error: 'd' was not declared in this scope
  118 |         q.push(P((p.fi-1)/5,p.se+c+d));
      |                                    ^
a.cc:120:10: error: 'p' was not declared in this scope
  120 |       if(p.fi%5==2){
      |          ^
a.cc:121:34: error: 'c' was not declared in this scope
  121 |         q.push(P((p.fi-2)/5,p.se+c+d+d));
      |                                  ^
a.cc:121:36: error: 'd' was not declared in this scope
  121 |         q.push(P((p.fi-2)/5,p.se+c+d+d));
      |                                    ^
a.cc:123:10: error: 'p' was not declared in this scope
  123 |       if(p.fi%5==3){
      |          ^
a.cc:124:34: error: 'c' was not declared in this scope
  124 |         q.push(P((p.fi+2)/5,p.se+c+d+d));
      |                                  ^
a.cc:124:36: error: 'd' was not declared in this scope
  124 |         q.push(P((p.fi+2)/5,p.se+c+d+d));
      |                                    ^
a.cc:126:10: error: 'p' was not declared in this scope
  126 |       if(p.fi%5==4){
      |          ^
a.cc:127:34: error: 'c' was not declared in this scope
  127 |         q.push(P((p.fi+1)/5,p.se+c+d));
      |                                  ^
a.cc:127:36: error: 'd' was not declared in this scope
  127 |         q.push(P((p.fi+1)/5,p.se+c+d));
      |                                    ^
a.cc:133:5: error: 'cout' was not declared in this scope
  133 |     cout<<ans<<endl;
      |     ^~~~
a.cc:133:11: error: 'ans' was not declared in this scope
  133 |     cout<<ans<<endl;
      |           ^~~
a.cc:133:16: error: 'endl' was not declared in this scope
  133 |     cout<<ans<<endl;
      |                ^~~~