1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "bits/stdc++.h" // Ignacy Boehlke
using namespace std;     // XIII LO Szczecin
template<class A, class B> ostream& operator << (ostream& os, const pair<A, B>& p) {return os << '{' << p.first << ", " << p.second << '}';}
template<class T> auto operator << (ostream& os, const T& v) -> decltype(v.begin(), os) {os << '{';for (auto i : v) os << i << ", ";return os << '}';}
#ifdef DEBUG
#define D(x...) x
#else
#define D(x...)
#endif
#define LN(x) D(cerr << #x << ": " << x << ' ')
#define LOG(x) D(cerr << #x << ": " << x << '\n')
#define ssize(x) ((int)x.size())
#define FOR(a, b, c) for(int a = (b); a <= (c); ++a)
#define REP(a, b) FOR(a, 0, b - 1)
#define ALL(x) (x).begin(), (x).end()
#define fi first
#define se second
using ll = long long;

int main() {
    array<int, 3> lim, st;
    REP(i, 3) scanf("%d", &lim[i]);
    REP(i, 3) scanf("%d", &st[i]);
    vector<int> res(lim[2] + 1, -1);
    queue<pair<int, array<int, 3>>> Q;
    set<array<int, 3>> vis;
    Q.emplace(0, st);
    while (!Q.empty()) {
        auto [t, arr] = Q.front();
        Q.pop();
        REP(i, 3) if (res[arr[i]] == -1) res[arr[i]] = t;
        REP(a, 3) REP(b, 3) if (a != b) {
            array<int, 3> tmp = arr;
            if (tmp[a] <= lim[b] - tmp[b]) {
                tmp[b] += tmp[a];
                tmp[a] = 0;
            } else {
                tmp[a] -= lim[b] - tmp[b];
                tmp[b] = lim[b];
            }
            if (!vis.count(tmp)) {
                vis.emplace(tmp);
                Q.emplace(t + 1, tmp);
            }
        }
    }
    REP(i, lim[2] + 1) printf("%d ", res[i]);
    putchar('\n');
}