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
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include <bits/stdc++.h>

#define ll long long
#define str string
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second

#define vc vector<char>
#define vvc vector<vc>
#define vi vector<int>
#define vvi vector<vi>
#define vvvi vector<vvi>
#define vvvvi vector<vvvi>
#define vll vector<ll>
#define vvll vector<vll>
#define vvvll vector<vvll>
#define vvvvll vector<vvvll>
#define vs vector<str>
#define vvs vector<vs>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define vpll vector<pll>
#define vvpll vector<vpll>
#define vb vector<bool>
#define vvb vector<vb>
#define rep(i, a, b) for (int i = (a); i < int(b); i++)
#define repi(i, a, b) for (int i = (a); i <= int(b); i++)

using namespace std;
int A, B, C;
int a, b, c;

#define triple pair<int, pair<int, int>>
#define aa fi
#define bb se.fi
#define cc se.se

void solve() {
    cin >> A >> B >> C;
    cin >> a >> b >> c;

    int limits[3] = {A, B, C};

    map<triple, int> dist;
    dist[{a, {b, c}}] = 0;

    queue<pair<triple, int>> q;
    q.push({{a, {b, c}}, 0});

    while (!q.empty()) {
        int d = q.front().se;
        triple t = q.front().fi;
        q.pop();

        int tr[3] = {t.aa, t.bb, t.cc};

        rep(i, 0, 3) {
            int cnt = 0;
            for (int j = (i + 1) % 3; cnt < 2; cnt++, j = (j + 1) % 3) {

                int new_tr[3] = {tr[0], tr[1], tr[2]};

                // pour from i to j
                int amount = min(limits[j] - tr[j], tr[i]);

                new_tr[i] -= amount;
                new_tr[j] += amount;

                triple new_triple = {new_tr[0], {new_tr[1], new_tr[2]}};
                if (!dist.count(new_triple)) {
                    dist[new_triple] = d + 1;
                    q.push({new_triple, d + 1});
                }
            }
        }
    }

    vi dist_k(C + 1, 1e9);

    for (auto & dt : dist) {
        triple tr = dt.first;
        int dist_val = dt.second;

        dist_k[tr.aa] = min(dist_k[tr.aa], dist_val);
        dist_k[tr.bb] = min(dist_k[tr.bb], dist_val);
        dist_k[tr.cc] = min(dist_k[tr.cc], dist_val);
    }

    repi(i, 0, C) {
        if (dist_k[i] == 1e9) cout << -1;
        else cout << dist_k[i];
        cout << " ";
    }
}


int main() {

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    bool _multipleTestCases = false;

    if (_multipleTestCases) {
        ll t; cin >> t;
        while (t--)
            solve();
    }
    else {
        solve();
    }

    return 0;
}