#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
long long ex_gcd(long long a, long long b, long long *x, long long *y);

int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #endif
    long long n, c1, c2, n1, n2;
    long long m1, m2, x, y, d, t, t1, t2;

    while(cin>>n && n!=0){
        cin>> c1 >> n1 >> c2 >> n2;
        d = ex_gcd(n1, n2, &x, &y);
        if(n%d!=0 || (n<n1 && n<n2) ){
            cout << "failed\n";
            continue;
        }

        t1 = ceil(-n*x/n2);
        t2 = floor(n*y/n1);

        if(t1>t2){
            cout << "failed\n";
            continue;
        }
        if(c1*n2/d-c2*n1/d>=0)
            t=t1;
        else
            t=t2;

        m1 = n*x/d + n2/d*t;
        m2 = n*y/d - n1/d*t;
        cout << m1 << " " << m2 << endl;
    }
    return 0;
}

long long ex_gcd(long long a, long long b, long long *x, long long *y){
    long long tmp, r, p, lx, ly, rx, ry, first=1;
    if(a<b)
        return ex_gcd(b, a, y, x);
    else{
        lx=1; ly=0;
        rx=0; ry=1;
        while(b!=0){
            p=a/b; r=a%b;
            a=b; b=r;
            if(b==0 && first){
                lx=0; ly=1;
                break;
            }
            if(b>0){
                first=0;
                lx -= p*rx; ly -= p*ry;
                if(a%b!=0){
                    tmp=lx; lx=rx; rx=tmp;
                    tmp=ly; ly=ry; ry=tmp;
                }
            }
        }
        *x=lx; *y=ly;
        return a;
    }
}
