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
#include <bits/stdc++.h>

#define fi first
#define se second
#define p_b push_back
#define pll pair<ll,ll>
#define pii pair<int,int>
#define m_p make_pair
#define all(x) x.begin(),x.end()
#define sset ordered_set
#define sqr(x) (x)*(x)
#define pw(x) (1ll << (x))
#define sz(x) (int)x.size()
#define fout(x) {cout << x << "\n"; return; }

using namespace std;
typedef long long ll;
typedef long double ld;
const int MAXN = 1e5;
const int M = pw(16);
const long long mod = 1e9 + 7;
const int N = 5e5;
const int inf = 1e9;
template <typename T> void vout(T s){cout << s << endl;exit(0);}



int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int a, b, c, A, B, C;
    cin >> A >> B >> C >> a >> b >> c;

    vector <int> f(C + 1, inf);

    vector <pii> arr;    

    arr.p_b({A, a});
    arr.p_b({B, b});
    arr.p_b({C, c});

    map <vector <pii>, int> mp;    

    queue < vector <pii> > q;

    mp[arr] = 0;
    q.push(arr);

    int step = 0;

    while(!q.empty()){
        vector <pii> xe = q.front();
        q.pop();
        step++;
        int val = mp[xe];
        
        for(auto j : xe) f[j.se] = min(f[j.se], val);

        for(int i1 = 0; i1 < 3; i1++)
            for(int i2 = 0; i2 < 3; i2++) if(i1 != i2){
                int k = min(xe[i2].fi - xe[i2].se, xe[i1].se);         
                xe[i2].se += k;
                xe[i1].se -= k;                
                if(mp.find(xe) == mp.end()){                    
                    q.push(xe);                    
                    mp[xe] = val + 1;
                }
                xe[i2].se -= k;
                xe[i1].se += k;
            }
    }   

    for(int i = 0; i <= C; i++){
        if(f[i] == inf) f[i] = -1;
        cout << f[i] << " ";
    }

    cout << "\n";

    return 0;
}