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

ll x, y, d;

void extendedEuclid(ll a, ll b) {
    if (b == 0) {
        x = 1;
        y = 0;
        d = a;
        return;
    }
    extendedEuclid(b, a % b);
    ll y1 = x - (a / b) * y;
    x = y;
    y = y1;
}

int main() {
    ll v, n1, n2, c1, c2;
    while (cin >> v && v) {
        cin >> c1 >> n1 >> c2 >> n2;
        extendedEuclid(n1, n2);

        if (v % d != 0) {
            cout << "failed\n";
        } else {
            x *= v / d;
            y *= v / d;

            n2 /= d;
            n1 /= d;

            ll l = ceil(-(double)x / n2);
            ll r = floor((double)y / n1);

            if (l <= r) {
                ll x1 = x + n2 * l;
                ll y1 = y - n1 * l;
                ll cost1 = c1 * x1 + c2 * y1;

                ll x2 = x + n2 * r;
                ll y2 = y - n1 * r;
                ll cost2 = c1 * x2 + c2 * y2;

                if (cost1 < cost2) {
                    cout << x1 << " " << y1 << '\n';
                } else {
                    cout << x2 << " " << y2 << '\n';
                }
            } else {
                cout << "failed\n";
            }
        }
    }
    return 0;
}