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
#include <bits/stdc++.h>
#define fi first
#define sc second
#define forn(i,p,k) for(int i=(p);i<=(k);++i)
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MM = 100013;
const int inf = 1e9+13;
int A,B,C,S;
int ans[MM];
map<pair<int,int>, bool> vis; //c,b,a = S-c-b
queue< pair<pair<int,int>,int> > Q; //cords, dist
void BFS(int a, int b, int c) {
    Q.push({{c,b},0});
    vis[{c,b}] = true;
    int k;
    while(!Q.empty()) {
        auto v = Q.front();
        Q.pop();
        c = v.fi.fi;
        b = v.fi.sc;
        a = S - b - c;
        // cerr<<a<<" "<<b<<" "<<c<<"\n";
        ans[a] = min(ans[a], v.sc);
        ans[b] = min(ans[b], v.sc);
        ans[c] = min(ans[c], v.sc);
        // a->b
        if (a != 0 && b != B) {
            k = min(B-b, a);
            bool &tmp = vis[{c,b+k}];
            if(tmp == false) {
                tmp = true;
                Q.push({{c,b+k},v.sc+1});
            }
        }
        // a->c
        if (a != 0 && c != C) {
            k = min(C-c, a);
            bool &tmp = vis[{c+k,b}];
            if(tmp == false) {
                tmp = true;
                Q.push({{c+k,b},v.sc+1});
            }
        }
        // b->a
        if (b != 0 && a != A) {
            k = min(A-a, b);
            bool &tmp = vis[{c,b-k}];
            if(tmp == false) {
                tmp = true;
                Q.push({{c,b-k},v.sc+1});
            }
        }
        // b->c
        if (b != 0 && c != C) {
            k = min(C-c, b);
            bool &tmp = vis[{c+k,b-k}];
            if(tmp == false) {
                tmp = true;
                Q.push({{c+k,b-k},v.sc+1});
            }
        }
        // c->a
        if (c != 0 && a != A) {
            k = min(A-a, c);
            bool &tmp = vis[{c-k,b}];
            if(tmp == false) {
                tmp = true;
                Q.push({{c-k,b},v.sc+1});
            }
        }
        // c->b
        if (c != 0 && b != B) {
            k = min(B-b, c);
            bool &tmp = vis[{c-k,b+k}];
            if(tmp == false) {
                tmp = true;
                Q.push({{c-k,b+k},v.sc+1});
            }
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    int a,b,c;
    cin>>A>>B>>C>>a>>b>>c;
    S = a+b+c;
    forn(i,0,C) ans[i] = inf;
    BFS(a,b,c);
    forn(i,0,C) cout<<(ans[i] == inf ? -1 : ans[i])<<' ';
    cout<<'\n';
    return 0;
}