Language: C++

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n)-1;(i)>=0;(i)--)
#define all(v) (v).begin(),(v).end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define pb push_back
#define MOD 1000000007
#define inf 1000000000
#define llinf 1000000000000000
#define MAX 1000000


typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef vector<pint> vpint;


ll def(ll x1,ll x2,ll y){
    if(x1>=x2)return 0;
    ll z=y-y%x1;
    return z/x1*x2-z;   
}


int main () {
    ll n,a1,a2,b1,b2,c1,c2;
    cin>>n>>a1>>b1>>c1>>a2>>b2>>c2;
    ll newn=n;
    double ap=(double)a1/a2;
    double bp=(double)b1/b2;
    double cp=(double)c1/c2;
    //a
    if(ap>=bp && ap>=cp && ap>1){
        newn+=def(a1,a2,n);
        n=n%a1;
        //b
        if(bp>=cp && bp>1){
            newn+=def(b1,b2,n);
            n=n%b1;         
            //c
            if(cp>1){
                newn+=def(c1,c2,n);
                n=n%c1;         
            }           
        }
        //c
        else if(cp>1){
            newn+=def(c1,c2,n);;
            n=n%c1;         
            //b
            if(bp>1){
                newn+=def(b1,b2,n);
                n=n%b1;         
            }           
        }
    }
    else if(bp>=cp && bp>1){
        newn+=def(b1,b2,n);
        n=n%b1;
        //a
        if(ap>=cp && ap>1){
            newn+=def(a1,a2,n);
            n=n%a1;         
            //c
            if(cp>1){
                newn+=def(c1,c2,n);
                n=n%c1;         
            }           
        }
        //c
        else if(cp>1){
            newn+=def(c1,c2,n);;
            n=n%c1;         
            //a
            if(ap>1){
                newn+=def(a1,a2,n);
                n=n%a1;         
            }           
        }
    }
    else if(cp>1){
        newn+=def(c1,c2,n);
        n=n%c1;
        //a
        if(ap>=bp && ap>1){
            newn+=def(a1,a2,n);
            n=n%a1;         
            //b
            if(bp>1){
                newn+=def(b1,b2,n);
                n=n%b1;         
            }           
        }
        //b
        else if(bp>1){
            newn+=def(b1,b2,n);;
            n=n%b1;         
            //a
            if(ap>1){
                newn+=def(a1,a2,n);
                n=n%a1;         
            }           
        }
    }
    //cout<<newn<<endl;
    n=newn;
    newn=newn;
    swap(a1,a2);
    swap(b1,b2);
    swap(c1,c2);
    double ap=(double)a1/a2;
    double bp=(double)b1/b2;
    double cp=(double)c1/c2;
    //a
    if(ap>=bp && ap>=cp && ap>1){
        newn+=def(a1,a2,n);
        n=n%a1;
        //b
        if(bp>=cp && bp>1){
            newn+=def(b1,b2,n);
            n=n%b1;         
            //c
            if(cp>1){
                newn+=def(c1,c2,n);
                n=n%c1;         
            }           
        }
        //c
        else if(cp>1){
            newn+=def(c1,c2,n);;
            n=n%c1;         
            //b
            if(bp>1){
                newn+=def(b1,b2,n);
                n=n%b1;         
            }           
        }
    }
    else if(bp>=cp && bp>1){
        newn+=def(b1,b2,n);
        n=n%b1;
        //a
        if(ap>=cp && ap>1){
            newn+=def(a1,a2,n);
            n=n%a1;         
            //c
            if(cp>1){
                newn+=def(c1,c2,n);
                n=n%c1;         
            }           
        }
        //c
        else if(cp>1){
            newn+=def(c1,c2,n);;
            n=n%c1;         
            //a
            if(ap>1){
                newn+=def(a1,a2,n);
                n=n%a1;         
            }           
        }
    }
    else if(cp>1){
        newn+=def(c1,c2,n);
        n=n%c1;
        //a
        if(ap>=bp && ap>1){
            newn+=def(a1,a2,n);
            n=n%a1;         
            //b
            if(bp>1){
                newn+=def(b1,b2,n);
                n=n%b1;         
            }           
        }
        //b
        else if(bp>1){
            newn+=def(b1,b2,n);;
            n=n%b1;         
            //a
            if(ap>1){
                newn+=def(a1,a2,n);
                n=n%a1;         
            }           
        }
    }  
    cout<<newn<<endl;


}

Compiler output:
a.cc: In function 'int main()':
a.cc:118:12: error: redeclaration of 'double ap'
  118 |     double ap=(double)a1/a2;
      |            ^~
a.cc:36:12: note: 'double ap' previously declared here
   36 |     double ap=(double)a1/a2;
      |            ^~
a.cc:119:12: error: redeclaration of 'double bp'
  119 |     double bp=(double)b1/b2;
      |            ^~
a.cc:37:12: note: 'double bp' previously declared here
   37 |     double bp=(double)b1/b2;
      |            ^~
a.cc:120:12: error: redeclaration of 'double cp'
  120 |     double cp=(double)c1/c2;
      |            ^~
a.cc:38:12: note: 'double cp' previously declared here
   38 |     double cp=(double)c1/c2;
      |            ^~