Problem:
Problem A:
The Balance
Ms. Iyo Kiffa-Australis has a balance and only two kinds of weights to measure a dose of medicine.
For example, to measure 200mg of aspirin using 300mg weights and 700mg weights, she can put
one 700mg weight on the side of the medicine and three 300mg weights on the opposite side
(Figure 1). Although she could put four 300mg weights on the medicine side and two 700mg
weights on the other (Figure 2), she would not choose this solution because it is less convenient
to use more weights.
You are asked to help her by calculating how many weights are required.
Figure 1: To measure 200mg of aspirin using three 300mg weights and one 700mg weight
Figure 2: To measure 200mg of aspirin using four 300mg weights and two 700mg weights
Input
The input is a sequence of datasets. A dataset is a line containing three positive integers
a
,
b
,
and
d
separated by a space. The following relations hold:
a
≠
b
,
a
≤ 10000,
b
≤ 10000, and
d
≤ 50000. You may assume that it is possible to measure
d
mg using a combination of
a
mg
and
b
mg weights. In other words, you need not consider “no solution” cases.
The end of the input is indicated by a line containing three zeros separated by a space. It is not
a dataset.
Output
The output should be composed of lines, each corresponding to an input dataset (
a
,
b
,
d
). An
output line should contain two nonnegative integers
x
and
y
separated by a space. They should
satisfy the following three conditions.
You can measure
d
mg using
x
many
a
mg weights and
y
many
b
mg weights.
The total number of weights (
x
+
y
) is the smallest among those pairs of nonnegative
  integers satisfying the previous condition.
The total mass of weights (
ax
+
by
) is the smallest among those pairs of nonnegative
  integers satisfying the previous two conditions.
No extra characters (e.g. extra spaces) should appear in the output.
Sample Input
700 300 200
500 200 300
500 200 500
275 110 330
275 110 385
648 375 4002
3 1 10000
0 0 0
Output for the Sample Input
1 3
1 1
1 0
0 3
1 1
49 74
3333 1

Submitted solutions:

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

ll EX_GCD(ll a, ll b, ll& x, ll& y) {
	ll d = a;
	if (b != 0) {
		d = EX_GCD(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

int main()
{
	ll a, b, d;
	while (cin >> a >> b >> d, a | b | d) {
		ll cx, cy;
		ll gcd = EX_GCD(a, b, cx, cy);
		a /= gcd; b /= gcd; d /= gcd;
		cx *= d, cy *= d;
		ll x = cx, y = cy;
		for (ll i = -100000; i <= 100000; i++) {
			if (abs(cx + b * i) + abs(cy - a * i) < abs(x) + abs(y) || (abs(cx + b * i) + abs(cy - a * i) == abs(x) + abs(y) && abs(cx + b * i) * a + abs(cy - a * i) * b < abs(x) * a + abs(y) * b)) {
				x = cx + b * i;
				y = cy - a * i;
			}
		}
		cout << abs(x) << ' ' << abs(y) << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3288
final_rank: 5

code_snippet: #include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;

const int INF = 1012345678;

int main() {
	while (true) {
		int A, B, D;
		cin >> A >> B >> D;
		if (A == 0 && B == 0 && D == 0) {
			break;
		}
		int optx = INF, opty = INF;
		for (int a = 0; a <= B + D; a++) {
			for (int p = -D; p <= +D; p += 2 * D) {
				int z = a * A + p;
				if (abs(z) % B == 0) {
					int b = abs(z) / B;
					if (optx + opty > a + b || (optx + opty == a + b && A * optx + B * opty > A * a + B * b)) {
						optx = a;
						opty = b;
					}
				}
			}
		}
		cout << optx << ' ' << opty << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3320
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(a) a.begin(),a.end()
#define reps(i, a, n) for (int i = (a); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)
#define rreps(i, a, n) for (int i = (a); i > (int)(n); i--)
const long long mod = 1000000007;
const long long INF = 1e18;
ll myceil(ll a, ll b) {return (a+b-1)/b;}

int a,b,d;

void solve() {
    pair<int,int> ans = {1e9,1e9};
    ll weight = 0;
    for (int i = 0; i <= 1e5; i++) {
        if (abs(i*a-d)%b == 0) {
            if (ans.first + ans.second > i+abs(i*a-d)/b) {
                ans.first = i;
                ans.second = abs(i*a-d)/b;
                weight = d;
            }
            else if (ans.first + ans.second == i+abs(i*a-d)/b){
                if (weight > d) {
                    ans.first = i;
                    ans.second = abs(i*a-d)/b;
                    weight = d;
                }
            }
        }

        if ((i*a+d)%b == 0) {
            if (ans.first + ans.second > i+(i*a+d)/b) {
                ans.first = i;
                ans.second = (i*a+d)/b;
                weight = i*a+d+i*a;
            }
            else if (ans.first + ans.second == i+(i*a+d)/b){
                if (weight > d) {
                    ans.first = i;
                    ans.second = (i*a+d)/b;
                    weight = i*a+d+i*a;
                }
            }
        }
    }

    cout << ans.first << ' ' << ans.second << endl;
    return;

}


int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    cin >> a >> b >> d;
    while (a != 0) {
        solve();
        cin >> a >> b >> d;
    }
}
accuracy: 1
time_ms: 30
memory_kb: 3368
final_rank: 6

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

#include <unistd.h>

namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf


uint32_t pil = 0, pir = 0, por = 0;

struct Pre {
    char num[10000][4];
    constexpr Pre() : num() {
        for (int i = 0; i < 10000; i++) {
            int n = i;
            for (int j = 3; j >= 0; j--) {
                num[i][j] = n % 10 | '0';
                n /= 10;
            }
        }
    }
} constexpr pre;

inline void load() {
    memmove(ibuf, ibuf + pil, pir - pil);
    pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
    pil = 0;
    if (pir < SZ)
        ibuf[pir++] = '\n';
}

inline void flush() {
    fwrite(obuf, 1, por, stdout);
    por = 0;
}

void rd(char &c) {
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
}

void rd(string &x) {
    x.clear();
    char c;
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
    do {
        x += c;
        if (pil == pir)
            load();
        c = ibuf[pil++];
    } while (!isspace(c));
}

template <typename T> void rd_real(T &x) {
    string s;
    rd(s);
    x = stod(s);
}

template <typename T> void rd_integer(T &x) {
    if (pil + 100 > pir)
        load();
    char c;
    do
        c = ibuf[pil++];
    while (c < '-');
    bool minus = 0;
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (c == '-') {
            minus = 1, c = ibuf[pil++];
        }
    }
    x = 0;
    while ('0' <= c) {
        x = x * 10 + (c & 15), c = ibuf[pil++];
    }
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (minus)
            x = -x;
    }
}

void rd(int &x) {
    rd_integer(x);
}
void rd(ll &x) {
    rd_integer(x);
}
void rd(i128 &x) {
    rd_integer(x);
}
void rd(uint &x) {
    rd_integer(x);
}
void rd(ull &x) {
    rd_integer(x);
}
void rd(u128 &x) {
    rd_integer(x);
}
void rd(double &x) {
    rd_real(x);
}
void rd(long double &x) {
    rd_real(x);
}

template <class T, class U> void rd(pair<T, U> &p) {
    return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T> void rd_tuple(T &t) {
    if constexpr (N < std::tuple_size<T>::value) {
        auto &x = std::get<N>(t);
        rd(x);
        rd_tuple<N + 1>(t);
    }
}
template <class... T> void rd(tuple<T...> &tpl) {
    rd_tuple(tpl);
}

template <size_t N = 0, typename T> void rd(array<T, N> &x) {
    for (auto &d : x)
        rd(d);
}
template <class T> void rd(vector<T> &x) {
    for (auto &d : x)
        rd(d);
}

void read() {}
template <class H, class... T> void read(H &h, T &...t) {
    rd(h), read(t...);
}

void wt(const char c) {
    if (por == SZ)
        flush();
    obuf[por++] = c;
}
void wt(const string s) {
    for (char c : s)
        wt(c);
}
void wt(const char *s) {
    size_t len = strlen(s);
    for (size_t i = 0; i < len; i++)
        wt(s[i]);
}

template <typename T> void wt_integer(T x) {
    if (por > SZ - 100)
        flush();
    if (x < 0) {
        obuf[por++] = '-', x = -x;
    }
    int outi;
    for (outi = 96; x >= 10000; outi -= 4) {
        memcpy(out + outi, pre.num[x % 10000], 4);
        x /= 10000;
    }
    if (x >= 1000) {
        memcpy(obuf + por, pre.num[x], 4);
        por += 4;
    } else if (x >= 100) {
        memcpy(obuf + por, pre.num[x] + 1, 3);
        por += 3;
    } else if (x >= 10) {
        int q = (x * 103) >> 10;
        obuf[por] = q | '0';
        obuf[por + 1] = (x - q * 10) | '0';
        por += 2;
    } else
        obuf[por++] = x | '0';
    memcpy(obuf + por, out + outi + 4, 96 - outi);
    por += 96 - outi;
}

template <typename T> void wt_real(T x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << double(x);
    string s = oss.str();
    wt(s);
}

void wt(int x) {
    wt_integer(x);
}
void wt(ll x) {
    wt_integer(x);
}
void wt(i128 x) {
    wt_integer(x);
}
void wt(uint x) {
    wt_integer(x);
}
void wt(ull x) {
    wt_integer(x);
}
void wt(u128 x) {
    wt_integer(x);
}
void wt(double x) {
    wt_real(x);
}
void wt(long double x) {
    wt_real(x);
}

template <class T, class U> void wt(const pair<T, U> val) {
    wt(val.first);
    wt(' ');
    wt(val.second);
}
template <size_t N = 0, typename T> void wt_tuple(const T t) {
    if constexpr (N < std::tuple_size<T>::value) {
        if constexpr (N > 0) {
            wt(' ');
        }
        const auto x = std::get<N>(t);
        wt(x);
        wt_tuple<N + 1>(t);
    }
}
template <class... T> void wt(tuple<T...> tpl) {
    wt_tuple(tpl);
}
template <class T, size_t S> void wt(const array<T, S> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}
template <class T> void wt(const vector<T> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}

void print() {
    wt('\n');
}
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
    wt(head);
    if (sizeof...(Tail))
        wt(' ');
    print(forward<Tail>(tail)...);
}
void __attribute__((destructor)) _d() {
    flush();
}
} // namespace fastio


using fastio::flush;
using fastio::print;
using fastio::read;

inline void first(bool i = true) {
    print(i ? "first" : "second");
}
inline void Alice(bool i = true) {
    print(i ? "Alice" : "Bob");
}
inline void Takahashi(bool i = true) {
    print(i ? "Takahashi" : "Aoki");
}
inline void yes(bool i = true) {
    print(i ? "yes" : "no");
}
inline void Yes(bool i = true) {
    print(i ? "Yes" : "No");
}
inline void No() {
    print("No");
}
inline void YES(bool i = true) {
    print(i ? "YES" : "NO");
}
inline void NO() {
    print("NO");
}
inline void Yay(bool i = true) {
    print(i ? "Yay!" : ":(");
}
inline void Possible(bool i = true) {
    print(i ? "Possible" : "Impossible");
}
inline void POSSIBLE(bool i = true) {
    print(i ? "POSSIBLE" : "IMPOSSIBLE");
}

/**
 * @brief Fast IO
 */

int main() {
while(1) {
    ll A, B, C;
    cin >> A >> B >> C;
    if (A == 0 && B == 0 && C == 0) return 0;
    ll X = inf, Y = inf;
    rep(i,0,1000000) {
        ll D = A*(ll)i;
        if ((D+C)%B==0) {
            ll NA = i, NB = (D+C)/B;
            if (NA+NB<X+Y) {
                X=NA,Y=NB;
            }
            else if (NA+NB==X+Y && NA*A+NB*B<X*A+Y*B) {
                X=NA,Y=NB;
            }
        }
        if (abs(D-C)%B==0) {
            ll NA = i, NB = abs(D-C)/B;
            if (NA+NB<X+Y) {
                X=NA,Y=NB;
            }
            else if (NA+NB==X+Y && NA*A+NB*B<X*A+Y*B) {
                X=NA,Y=NB;
            }
        }
    }
    cout << X << ' ' << Y << endl;
}
}
accuracy: 1
time_ms: 1160
memory_kb: 3108
final_rank: 14

code_snippet: #include <algorithm>
#include <iostream>
#include <string>
#include <vector>

#define ll long long

using namespace std;
int main() {
    while (1) {
        ll a, b, d, x, x1,x2,y, y1, y2, mink = 1 << 30, ming = 1 << 30;
        cin >> a >> b >> d;
        if (a == 0 && b == 0 && d == 0) {
            break;
        }

        for (ll i = 0; i < 25001; i++) {
            if (abs(d - a * i) % b == 0) {
                y1 = abs(d - a * i) / b;
                if (i + y1 <= mink && (a * i + b * y1) <= ming) {
                    x = i;
                    y = y1;
                    mink = i + y1;
                    ming = a * i + b * y1;
                }
            }
            if ((d + a * i) % b == 0) {
                y2 = (d + a * i) / b;
                if (i + y2 <= mink && (a * i + b * y2) <= ming) {
                    x = i;
                    y = y2;
                    mink = i + y2;
                    ming = a * i + b * y2;
                }
            }
        }

        for (ll i = 0; i < 25001; i++) {
            if (abs(d - b * i) % a == 0) {
                x1 = abs(d - b* i) / a;
                if (i + x1 <= mink && (a * x1 + b * i) <= ming) {
                    x = x1;
                    y = i;
                    mink = i + x1;
                    ming = a * x1 + b * i;
                }
            }
            if ((d + b * i) % a == 0) {
                x2 = (d + b * i) / a;
                if (i + x2 <= mink && (a * x2 + b * i) <= ming) {
                    x = x2;
                    y = i;
                    mink = i + x2;
                    ming = a * x2 + b * i;
                }
            }
        }
        cout << x << " " << y << endl;
    }
}
accuracy: 1
time_ms: 70
memory_kb: 3104
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vvvvll = vector<vvvll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
#define all(A) A.begin(),A.end()
#define ALL(A) A.begin(),A.end()
#define rep(i, n) for (ll i = 0; i < (ll) (n); i++)
using pqr = priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>;

template<class T>
bool chmax(T& p, T q, bool C = 1) {
    if (C == 0 && p == q) {
        return 1;
    }
    if (p < q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

template<class T>
bool chmin(T& p, T q, bool C = 1) {
    if (C == 0 && p == q) {
        return 1;
    }
    if (p > q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

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

vector<ll> fact, factinv, inv;
ll mod = 1e9 + 7;
void prenCkModp(ll n) {
    fact.resize(n + 5);
    factinv.resize(n + 5);
    inv.resize(n + 5);
    fact.at(0) = fact.at(1) = 1;
    factinv.at(0) = factinv.at(1) = 1;
    inv.at(1) = 1;
    for (ll i = 2; i < n + 5; i++) {
        fact.at(i) = (fact.at(i - 1) * i) % mod;
        inv.at(i) = mod - (inv.at(mod % i) * (mod / i)) % mod;
        factinv.at(i) = (factinv.at(i - 1) * inv.at(i)) % mod;
    }

}
ll nCk(ll n, ll k) {
    if (k < 0)return 0;
    if (n < k) return 0;
    return fact.at(n) * (factinv.at(k) * factinv.at(n - k) % mod) % mod;
}
namespace atcoder {

    namespace internal {

        // @param n `0 <= n`
        // @return minimum non-negative `x` s.t. `n <= 2**x`
        int ceil_pow2(int n) {
            int x = 0;
            while ((1U << x) < (unsigned int)(n)) x++;
            return x;
        }

        // @param n `1 <= n`
        // @return minimum non-negative `x` s.t. `(n & (1 << x)) != 0`
        int bsf(unsigned int n) {
#ifdef _MSC_VER
            unsigned long index;
            _BitScanForward(&index, n);
            return index;
#else
            return __builtin_ctz(n);
#endif
        }

    }  // namespace internal

}  // namespace atcoder

namespace atcoder {

    template <class S,
        S(*op)(S, S),
        S(*e)(),
        class F,
        S(*mapping)(F, S),
        F(*composition)(F, F),
        F(*id)()>
        struct lazy_segtree {
        public:
            lazy_segtree() : lazy_segtree(0) {}
            lazy_segtree(int n) : lazy_segtree(std::vector<S>(n, e())) {}
            lazy_segtree(const std::vector<S>& v) : _n(int(v.size())) {
                log = internal::ceil_pow2(_n);
                size = 1 << log;
                d = std::vector<S>(2 * size, e());
                lz = std::vector<F>(size, id());
                for (int i = 0; i < _n; i++) d[size + i] = v[i];
                for (int i = size - 1; i >= 1; i--) {
                    update(i);
                }
            }

            void set(int p, S x) {
                //assertrt(0 <= p && p < _n);
                p += size;
                for (int i = log; i >= 1; i--) push(p >> i);
                d[p] = x;
                for (int i = 1; i <= log; i++) update(p >> i);
            }

            S get(int p) {
                //assertrt(0 <= p && p < _n);
                p += size;
                for (int i = log; i >= 1; i--) push(p >> i);
                return d[p];
            }

            S prod(int l, int r) {
                //assertrt(0 <= l && l <= r && r <= _n);
                if (l == r) return e();

                l += size;
                r += size;

                for (int i = log; i >= 1; i--) {
                    if (((l >> i) << i) != l) push(l >> i);
                    if (((r >> i) << i) != r) push(r >> i);
                }

                S sml = e(), smr = e();
                while (l < r) {
                    if (l & 1) sml = op(sml, d[l++]);
                    if (r & 1) smr = op(d[--r], smr);
                    l >>= 1;
                    r >>= 1;
                }

                return op(sml, smr);
            }

            S all_prod() { return d[1]; }

            void apply(int p, F f) {
                //assertrt(0 <= p && p < _n);
                p += size;
                for (int i = log; i >= 1; i--) push(p >> i);
                d[p] = mapping(f, d[p]);
                for (int i = 1; i <= log; i++) update(p >> i);
            }
            void apply(int l, int r, F f) {
                //assertrt(0 <= l && l <= r && r <= _n);
                if (l == r) return;

                l += size;
                r += size;

                for (int i = log; i >= 1; i--) {
                    if (((l >> i) << i) != l) push(l >> i);
                    if (((r >> i) << i) != r) push((r - 1) >> i);
                }

                {
                    int l2 = l, r2 = r;
                    while (l < r) {
                        if (l & 1) all_apply(l++, f);
                        if (r & 1) all_apply(--r, f);
                        l >>= 1;
                        r >>= 1;
                    }
                    l = l2;
                    r = r2;
                }

                for (int i = 1; i <= log; i++) {
                    if (((l >> i) << i) != l) update(l >> i);
                    if (((r >> i) << i) != r) update((r - 1) >> i);
                }
            }

            template <bool (*g)(S)> int max_right(int l) {
                return max_right(l, [](S x) { return g(x); });
            }
            template <class G> int max_right(int l, G g) {
                //assertrt(0 <= l && l <= _n);
                //assertrt(g(e()));
                if (l == _n) return _n;
                l += size;
                for (int i = log; i >= 1; i--) push(l >> i);
                S sm = e();
                do {
                    while (l % 2 == 0) l >>= 1;
                    if (!g(op(sm, d[l]))) {
                        while (l < size) {
                            push(l);
                            l = (2 * l);
                            if (g(op(sm, d[l]))) {
                                sm = op(sm, d[l]);
                                l++;
                            }
                        }
                        return l - size;
                    }
                    sm = op(sm, d[l]);
                    l++;
                } while ((l & -l) != l);
                return _n;
            }

            template <bool (*g)(S)> int min_left(int r) {
                return min_left(r, [](S x) { return g(x); });
            }
            template <class G> int min_left(int r, G g) {
                //assertrt(0 <= r && r <= _n);
                //assertrt(g(e()));
                if (r == 0) return 0;
                r += size;
                for (int i = log; i >= 1; i--) push((r - 1) >> i);
                S sm = e();
                do {
                    r--;
                    while (r > 1 && (r % 2)) r >>= 1;
                    if (!g(op(d[r], sm))) {
                        while (r < size) {
                            push(r);
                            r = (2 * r + 1);
                            if (g(op(d[r], sm))) {
                                sm = op(d[r], sm);
                                r--;
                            }
                        }
                        return r + 1 - size;
                    }
                    sm = op(d[r], sm);
                } while ((r & -r) != r);
                return 0;
            }

        private:
            int _n, size, log;
            std::vector<S> d;
            std::vector<F> lz;

            void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }
            void all_apply(int k, F f) {
                d[k] = mapping(f, d[k]);
                if (k < size) lz[k] = composition(f, lz[k]);
            }
            void push(int k) {
                all_apply(2 * k, lz[k]);
                all_apply(2 * k + 1, lz[k]);
                lz[k] = id();
            }
    };

}  // 
using namespace atcoder;

struct S {
    ll a;
    int size;
};

struct F {
    ll a, b;
};

S op(S l, S r) { return S{ min(l.a,r.a), l.size + r.size }; }

S e() { return S{ ll(1e18), 0 }; }

S mapping(F l, S r) { return S{ r.a * l.a + r.size * l.b, r.size }; }

F composition(F l, F r) { return F{ r.a * l.a, r.b * l.a + l.b }; }

F id() { return F{ 1, 0 }; }

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

    while (1) {
        ll A, B, D;
        cin >> A >> B >> D;
        if (A == 0)return 0;
        for (ll d = 1; d <= D*10000; d++) {
            ll M = 1e17;
            ll AN = 1e17, BN = 1e17;
            for (ll a = 0; a <= d; a++) {
                ll b = d - a;
                if (a * A + b * B == D) {
                    if (chmin(M, D)) {
                        AN = a, BN = b;
                    }
                }
                if (abs(a * A - b * B) == D) {
                    if (chmin(M, a * A + b * B)) {
                        AN = a, BN = b;
                    }
                }
            }
            if (M < 1e16) {
                cout << AN << " " << BN << endl;
                break;
            }
        }
    }



}
accuracy: 1
time_ms: 650
memory_kb: 3148
final_rank: 13

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

int main(){
    ll a, b, d;
    while(cin >> a >> b >> d){
        if(a == 0 && b == 0 && d == 0)return 0;
        array<ll,2> minv = {1ll << 60, 1ll << 60}, ans;
        auto f = [&](ll x, ll v){
            if(v % b != 0)return;
            ll y = v / b;
            if(y < 0)return;
            if(x + y < minv[0]){
                minv[0] = x + y;
                minv[1] = a * x + b * y;
                ans[0] = x, ans[1] = y;
            }else if(x + y == minv[0] && a * x + b * y < minv[1]){
                minv[1] = a * x + b * y;
                ans[0] = x, ans[1] = y;
            }
        };
        for(ll x = 0; x <= 100 * d; x++){
            f(x, d - a * x);
            f(x, a * x - d);
            f(x, a * x + d);
        }
        cout << ans[0] << " " << ans[1] << '\n';
    }
}
accuracy: 1
time_ms: 3310
memory_kb: 3132
final_rank: 19

code_snippet: #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

long long ext_gcd(long long a, long long b, long long &x, long long &y){
	if(b == 0){ x = 1; y = 0; return a;}
	long long d = ext_gcd(b, a%b, y, x);
	y -= a / b * x;
	return d;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	
	// ax + by = d
	// a(x + b) + b(y - a) = d
	// a(x - b) + b(y + a) = d

	while(true) {
		ll a,b,d; cin >> a >> b >> d; if(a == 0 && b == 0 && d == 0) break;
		ll x,y,g = ext_gcd(a, b, x, y);
		a /= g; b /= g; d /= g;
		x *= d; y *= d;

		ll ansX = abs(x), ansY = abs(y);
		int range = 1000000;
		for(int i = -range; i <= +range; i++) {
			ll nx = abs(x + b * i), ny = abs(y - a * i);
			if(nx + ny < ansX + ansY || nx + ny == ansX + ansY && nx * a + ny * b < ansX * a + ansY * b)
				ansX = nx, ansY = ny;
		}
		cout << ansX << " " << ansY << endl;
	}
}
accuracy: 1
time_ms: 210
memory_kb: 3464
final_rank: 11

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

template <typename T>
T extgcd(T a, T b, T& x, T& y) {
    if (b) {
        T d = extgcd(b, a % b, y, x);
        y -= a / b * x;
        return d;
    } else {
        x = 1;
        y = 0;
        return a;
    }
}

int main() {
    ll a, b, d;
    while (cin >> a >> b >> d, a) {
        ll x, y, g;
        g = extgcd(a, b, x, y);
        a /= g;
        b /= g;
        d /= g;
        ll Xbest = 1e18, Ybest = 1e18;
        for (int i = -1e5; i < 1e5; i++) {
            ll X = abs(d * x + b * i), Y = abs(d * y - a * i);
            if (X + Y < Xbest + Ybest || (X + Y == Xbest + Ybest && a * X + b * Y < a * Xbest + b * Ybest))
                Xbest = X, Ybest = Y;
        }
        cout << Xbest << " " << Ybest << endl;
    }
}
accuracy: 1
time_ms: 20
memory_kb: 3416
final_rank: 8

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

int a, b, d;

void solve();

int main() {
  while (1) {
    cin >> a >> b >> d;
    if (!(a + b + d)) break;
    solve();
  }
  return 0;
}

void solve() {
  struct dat {
    int x, y, total;
    dat(int _x = 1e8, int _y = 1e8, int _t = 0) : x(_x), y(_y), total(_t) {}
    bool operator>(const dat& r) const {
      if (x + y != r.x + r.y) return x + y > r.x + r.y;
      return a * x + b * y > a * r.x + b * r.y;
    }
  };
  const int len = 200000;
  vector<dat> dp(len + 1);
  priority_queue<dat, vector<dat>, greater<dat>> pq;
  dp[0] = dat(0, 0, 0);
  pq.push(dp[0]);
  while (pq.size()) {
    auto [x, y, total] = pq.top();
    pq.pop();
    if (x != dp[total].x || y != dp[total].y) continue;
    for (int i = -1; i <= 1; ++i)
      for (int j = -1; j <= 1; ++j) {
        int tx = x + (i != 0), ty = y + (j != 0), to = total + i * a + j * b;
        if (to < 0 || to > len || !(dp[to] > dat(tx, ty, to))) continue;
        dp[to] = dat(tx, ty, to);
        pq.push(dp[to]);
      }
  }
  cout << dp[d].x << " " << dp[d].y << endl;
}
accuracy: 1
time_ms: 1300
memory_kb: 5448
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define db  double
#define ll  long long
#define Pir pair<ll, ll>
#define fi  first
#define se  second
#define pb  push_back
#define m_p make_pair
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
/*==========ACMer===========*/
ll a, b, c;

int main()
{
    while (scanf("%lld %lld %lld", &a, &b, &c) && a + b + c)
    {
        ll ans = inf, sum = 0; Pir num;
        for (int i = 0; i <= 10 * c; i ++)
        {
            ll tmp = abs(c - i * a);
            if (tmp % b == 0)
            {
                int j = tmp / b;
                if (i + j < ans)
                {
                    ans = i + j;
                    sum = i * a + j * b;
                    num = m_p(i, j);
                }
                else if (i + j == ans && i * a + j * b < sum)
                {
                    sum = i * a + j * b;
                    num = m_p(i, j);
                }
            }
        }

        for (int j = 0; j <= 10 * c; j ++)
        {
            ll tmp = abs(c - j * b);
            if (tmp % a == 0)
            {
                int i = tmp / a;
                if (i + j < ans)
                {
                    ans = i + j;
                    sum = i * a + j * b;
                    num = m_p(i, j);
                }
                else if (i + j == ans && i * a + j * b < sum)
                {
                    sum = i * a + j * b;
                    num = m_p(i, j);
                }
            }

        }

        printf("%lld %lld\n", num.fi, num.se);
    }

    return 0;
}
accuracy: 1
time_ms: 240
memory_kb: 3412
final_rank: 12

code_snippet: #include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <tuple>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <functional>
#include <numeric>
#include <iomanip> 
#include <stdio.h>
//eolibraries
#define lnf 3999999999999999999
#define inf 999999999
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ld long double
#define all(c) (c).begin(),(c).end()
#define sz(c) (ll)(c).size()
#define make_unique(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define pii pair <ll,ll>
#define rep(i,n) for(ll i = 0 ; i < n ; i++) 
#define drep(i,n) for(ll i = n-1 ; i >= 0 ; i--)
#define crep(i,x,n) for(ll i = x ; i < n ; i++)
#define vi vector <ll> 
#define vec(...) vector<__VA_ARGS__>
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
//eodefine
using namespace std;

const ll max_n = 103002;

int main(){
fcin;
	while(true){
		ll a,b,d;
		cin>>a>>b>>d;
		if(!a and !b and !d) break;
		ll ans=inf,ansx=0,ansy=0,p=0;
		
		function<void(ll,ll)> comp = [&](ll x,ll y){
			if(ans>x+y){
				ans=x+y;
				p=a*x+b*y;
				ansx=x,ansy=y;
			}else if(ans==x+y){
				if(a*x+b*y<p){
					p=a*x+b*y;
					ansx=x,ansy=y;
				}
			}
			return;
		};

		rep(x,50000){
			if((d-x*a)%b==0){
				ll y = (d-x*a)/b;
				if(x*a+y*b==d and y>=0){
					comp(x,y);
				}
			}
			if((d+x*a)%b==0){
				ll y = (d+x*a)/b;
				if(x*a+d==y*b and y>=0){
					comp(x,y);
				}
			}
			if((x*a-d)%b==0){
				ll y = (x*a-d)/b;
				// if(x==1)cout<<y<<"\n";
				if(x*a-d==y*b and y>=0){
					comp(x,y);
				}
			}
		}
		cout<<ansx<<" "<<ansy<<"\n";
	}
/*
*/
    return 0;   
}
accuracy: 1
time_ms: 80
memory_kb: 3296
final_rank: 7

code_snippet: #include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<stack>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> L_L;
const ll INF=2e18;
const ll MOD=1e9+7;

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

ll extgcd(ll a, ll b, ll c, ll& x, ll& y) {
    if (b == 0) {
        if(c%a!=0){
            x=INF;
            y=INF;
            return INF;
        }
        x=c/a;
        y=0;
        return a;
    }
    ll x0,y0;
    ll g=extgcd(b,a%b,c,x0,y0);
    x = y0;
    y = x0-(a/b)*y0;
    return g;
}

ll A,B,D;
ll Mass(L_L p){
    ll x=p.first;
    ll y=p.second;
    return A*abs(x)+B*abs(y);
}
bool GreaterA(L_L A,L_L B){
    ll aSum=abs(A.first)+abs(A.second);
    ll bSum=abs(B.first)+abs(B.second);
    if(aSum==bSum){
        return Mass(A) > Mass(B);
    }
    return aSum > bSum;
}
int main(){
    while(cin>>A>>B>>D,A!=0){
        ll g=gcd(gcd(A,B),D);
        A/=g; B/=g; D/=g;
        ll x,y;
        extgcd(A,B,D,x,y);
        L_L ans(x,y);
        for(ll i=-100000;i<=100000;i++){
            L_L now=L_L(x+B*i,y-A*i);
            if(GreaterA(ans,now)){
                ans=now;
            }
        }
        cout<<abs(ans.first)<<" "<<abs(ans.second)<<endl;
    }

    return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 3080
final_rank: 2

code_snippet: // #include <atcoder/all>
// using namespace atcoder;
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define rrep(i, n) for (int i = (int)n-1; i >= 0; --i)
using namespace std;
using ll = long long;
template<typename T>
inline bool chmax(T& a, const T& b) {
    if (a < b){
        a = b;
        return true;
    }
    return false;
}
template<typename T>
inline bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
/**
 * @brief 多次元 vector の作成
 * @author えびちゃん
 */
namespace detail {
    template<typename T, int N>
    auto make_vec(vector<int>& sizes, T const& x) {
        if constexpr (N == 1) {
            return vector(sizes[0], x);
        } else {
            int size = sizes[N-1];
            sizes.pop_back();
            return vector(size, make_vec<T, N-1>(sizes, x));
        }
    }
}
template<typename T, int N>
auto make_vec(int const(&sizes)[N], T const& x = T()) {
    vector<int> s(N);
    for (int i = 0; i < N; ++i) s[i] = sizes[N-i-1];
    return detail::make_vec<T, N>(s, x);
}
__attribute__((constructor))
void fast_io() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}



int solve() {
    ll a, b, c;
    cin >> a >> b >> c;
    if (a == 0) return 1;

    auto update = [&](ll& prex, ll& prey, ll newx, ll newy) {
        if (prex + prey > newx + newy) {
            prex = newx;
            prey = newy;
        } else if (prex + prey == newx + newy) {
            if (prex * a + prey * b > newx * a + newy * b) {
                prex = newx;
                prey = newy;
            }
        }
    };

    ll ansx = INT_MAX, ansy = INT_MAX;
    for (ll x = 0; x < 100000; ++x) {
        ll y;
        if (a * x - c >= 0 && (a * x - c) % b == 0) {
            y = (a * x - c) / b;
            update(ansx, ansy, x, y);
        }
        if ((a * x + c) % b == 0) {
            y = (a * x + c) / b;
            update(ansx, ansy, x, y);
        }
        if (c - a * x >= 0 && (c - a * x) % b == 0) {
            y = (c - a * x) / b;
            update(ansx, ansy, x, y);
        }
    }
    cout << ansx << ' ' << ansy << '\n';

    return 0;
}

int main() {
    while (!solve());
}
accuracy: 1
time_ms: 110
memory_kb: 3388
final_rank: 10

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "[";
  REP(i, SZ(v)) {
    if (i) os << ", ";
    os << v[i];
  }
  return os << "]";
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  return os << "(" << p.first << " " << p.second << ")";
}

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

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  while(1) {
    ll a, b, d; cin >> a >> b >> d;
    if(a == 0 && b == 0 && d == 0) break;

    ll mi1 = LINF;
    ll mi2 = LINF;
    ll ansx = 0, ansy = 0;
    REP(x, 1000000) {
      // left
      ll v = abs(d - a * x);
      if(v % b == 0) {
        ll y = v / b;
        if(mi1 > x + y || (mi1 == x + y && mi2 > a * x + b * y)) {
          chmin(mi1, x + y);
          chmin(mi2, a * x + b * y);
          ansx = x;
          ansy = y;
        }
      }

      // right
      v = abs(d + a * x);
      if(v % b == 0) {
        ll y = v / b;
        if(mi1 > x + y || (mi1 == x + y && mi2 > a * x + b * y)) {
          chmin(mi1, x + y);
          chmin(mi2, a * x + b * y);
          ansx = x;
          ansy = y;
        }
      }
    }
    cout << ansx << " " << ansy << endl;

  }

  return 0;
}
accuracy: 1
time_ms: 1230
memory_kb: 3356
final_rank: 16

code_snippet: #pragma GCC optimize("Ofast")
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <functional>
#include <cassert>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------

bool solve(){
  ll A,B,D;
  cin >> A >> B >> D;
  if(A==0 && B==0 && D==0) return false;
  ll x,y;
  pair<ll,ll> now(INF,INF);
  for(ll i=0; i<=1000000; i++){
    if(abs(A*i-D)%B == 0){
      ll nowX = i,nowY = abs(A*i-D)/B;
      if(chmin(now,pair<ll,ll>(nowX+nowY,nowX*A+nowY*B))){
        x = nowX;
        y = nowY;
      }
    }
    if(abs(B*i-D)%A == 0){
      ll nowX = i,nowY = abs(B*i-D)/A;
      if(chmin(now,pair<ll,ll>(nowX+nowY,nowX*A+nowY*B))){
        y = nowX;
        x = nowY;
      }
    }
  }
  cout << x << " " << y << "\n";
  return true; 
}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  while(solve());
  return 0;
}
accuracy: 1
time_ms: 1190
memory_kb: 3292
final_rank: 15

code_snippet: // I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
const ll INF = 1e15;
void solve(){
  ll a,b,d;
  ll v0=INF,v1=INF;
  ll ans_a=-1,ans_b=-1;
  cin >> a >> b >> d;
  if((a|b|d)==0) return;
  for(ll i=0;i<1e5;i++){
    ll na,nb;
    ll ax,bx;
    ll t_v0,t_v1;

    ax = i;
    na = a * i;
    if((na+d)%b==0){
      bx = (na+d)/b;
      nb = na+d;
      t_v0 = ax+bx;
      t_v1 = na+nb;
      if(v0>t_v0||(v0==t_v0&&t_v1<v1)){
        ans_a = ax;
        ans_b = bx;
        v0 = t_v0;
        v1 = t_v1;
      }
    }
    bx = i;
    nb = b * i;
    if((nb+d)%a==0){
      ax = (nb+d)/a;
      na = nb+d;
      t_v0 = ax+bx;
      t_v1 = na+nb;
      if(v0>t_v0||(v0==t_v0&&t_v1<v1)){
        ans_a = ax;
        ans_b = bx;
        v0 = t_v0;
        v1 = t_v1;
      }
    }
    if(d-nb>=0&&(d-nb)%a==0){
      ax = (d-nb)/a;
      na = d-nb;
      t_v0 = ax+bx;
      t_v1 = na+nb;
      if(v0>t_v0||(v0==t_v0&&t_v1<v1)){
        ans_a = ax;
        ans_b = bx;
        v0 = t_v0;
        v1 = t_v1;
      }
    }
  }
  cout << ans_a <<" "<<ans_b << endl;
  solve();
}
signed main(){
  init_io();
  solve();
}
accuracy: 1
time_ms: 120
memory_kb: 3264
final_rank: 9

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
const double pi = 3.141592653589793238462643383279;
using namespace std;
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a) * (a))
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

//repetition
//------------------------------------------
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define MOD 1000000007

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const double EPS = 1e-11, PI = acos(-1);
//ここから編集

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int A, B, D;
  while(cin >> A >> B >> D){
    if(A == 0 && B == 0 && D == 0) break;

    /* x+y が小さくなる */
    /* ax+byが小さくなる */

    map<int, pair<int, int>> dp;

    dp[D] = make_pair(0, 0);
    /* 0を目指す */

    priority_queue<pair<pair<int, int>, int>, vector<pair<pair<int, int>, int>>, greater<pair<pair<int, int>, int>>> q;
    q.push(make_pair(make_pair(0, 0), D));

    while(q.size()){
      auto p = q.top();
      q.pop();

      int xy  = p.first.first;
      int ax = p.first.second;
      int v = p.second;
      if(v == 0) break;
      if(dp[v] < make_pair(xy, ax)) continue;

      int nv = v+A;
      if(nv <= 50000){
        if(dp.find(nv) == dp.end()){
          dp[nv] = make_pair(xy+1, ax+A);
          q.push(make_pair(dp[nv], nv));
        }else{
          if(dp[nv] > make_pair(xy+1, ax+A)){
            dp[nv] = make_pair(xy+1, ax+A);
            q.push(make_pair(dp[nv], nv));
          }
        }
      }
      nv = v-A;
      if(nv >= -50000){
        if(dp.find(nv) == dp.end()){
          dp[nv] = make_pair(xy+1, ax+A);
          q.push(make_pair(dp[nv], nv));
        }else{
          if(dp[nv] > make_pair(xy+1, ax+A)){
            dp[nv] = make_pair(xy+1, ax+A);
            q.push(make_pair(dp[nv], nv));
          }
        }
      }
      nv = v+B;
      if(nv <= 50000){
        if(dp.find(nv) == dp.end()){
          dp[nv] = make_pair(xy+1, ax+B);
          q.push(make_pair(dp[nv], nv));
        }else{
          if(dp[nv] > make_pair(xy+1, ax+B)){
            dp[nv] = make_pair(xy+1, ax+B);
            q.push(make_pair(dp[nv], nv));
          }
        }
      }
      nv = v-B;
      if(nv >= -50000){
        if(dp.find(nv) == dp.end()){
          dp[nv] = make_pair(xy+1, ax+B);
          q.push(make_pair(dp[nv], nv));
        }else{
          if(dp[nv] > make_pair(xy+1, ax+B)){
            dp[nv] = make_pair(xy+1, ax+B);
            q.push(make_pair(dp[nv], nv));
          }
        }
      }
    }
    int X = dp[0].first;
    int Y = dp[0].second;

    int ans1=-1, ans2=-1;
    for(int i=0; i<=X; i++){
      int x = i, y = X-i;
      if(x*A + y*B == Y){
        ans1 = x, ans2 = y;
      }
    }
    cout << ans1 << " " << ans2 << endl;
  }
  return 0;
}
accuracy: 1
time_ms: 3180
memory_kb: 9296
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)

 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 

    int main(){
    while(true){
        lint a,b,c;
        cin>>a>>b>>c;
        if(a==0&&b==0&&c==0)break;
        lint w=INF,cost=INF,ans1,ans2;
        rep(i,1000000){
            lint x=a*i;
            lint d=abs(c-x);
            if(d%b==0){
                lint cmp=i+d/b;
                if(cost>cmp){
                    cost=cmp;
                    w=i*a+d;
                    ans1=i;
                    ans2=d/b;
                }else if(cost==cmp&&(i*a+d)<w){
                    cost=cmp;
                    w=i*a+d;
                    ans1=i;
                    ans2=d/b;
                }
            }
            d=abs(c+x);
            if(d%b==0){
                lint cmp=i+d/b;
                if(cost>cmp){
                    cost=cmp;
                    w=i*a+d;
                    ans1=i;
                    ans2=d/b;
                }else if(cost==cmp&&(i*a+d)<w){
                    cost=cmp;
                    w=i*a+d;
                    ans1=i;
                    ans2=d/b;
                }
            }
        }
        cout<<ans1<<" "<<ans2<<endl;
    }
    
    
    }
accuracy: 1
time_ms: 1470
memory_kb: 2988
final_rank: 17

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

template<typename T> T extgcd(T a,T b,T &x,T &y){
    T d=a;
    if (b!=0){
        d=extgcd(b,a%b,y,x);
        y-=(a/b)*x;
    } else x=1,y=0;
    return d;
}

void solve(int a,int b,int d){
    int x,y;
    ll g=extgcd(a,b,x,y);
    a/=g; b/=g; d/=g; x*=d; y*=d;
    ll ax=abs(x),ay=abs(y),sum=ax+ay,mass=a*ax+b*ay;
    auto update=[&](ll x,ll y){
        if (x+y<sum){
            sum=x+y; mass=a*x+b*y;
            ax=x; ay=y;
        } else if (a*x+b*y<mass){
            mass=a*x+b*y;
            ax=x; ay=y;
        }
    };
    for (int i=-50000;i<=50000;++i) update(abs(x-b*i),abs(y+a*i));

    cout << ax << ' ' << ay << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,d;
    while(cin >> a >> b >> d,a){
        solve(a,b,d);
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3144
final_rank: 1