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
#include <bits/stdc++.h>
#include <random>
#define ll long long int
#define pb push_back
#define st first
#define nd second
#define pii pair<int,int>
#define mp make_pair
#define pll pair<long long,long long>
#define ld long double
#define ull unsigned long long

using namespace std;

int mx[3];
int st[3];

const int nax = 1e5 + 5;
int ans[nax];

map<tuple<int, int, int>, int> dist;

void solve(){
    for(int i=0;i<3;i++) cin >> mx[i];
    for(int i=0;i<3;i++) cin >> st[i];
    fill(ans, ans + nax, 1e9);
    for(int i=0;i<3;i++){
        ans[st[i]] = 0;
    }
    vector<tuple<int, int, int> > Q;
    tuple<int, int, int> ini = make_tuple(st[0], st[1], st[2]);
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            if(i == j) continue;
            int safe[3];
            for(int k=0;k<3;k++) safe[k] = st[k];
            int moge = min(safe[i], mx[j] - safe[j]);
            safe[j] += moge;
            safe[i] -= moge;
            tuple<int, int, int> state = make_tuple(safe[0], safe[1], safe[2]);
            if(dist[state] == 0 && state != ini){
                dist[state] = 1;
                Q.pb(state);
            }
        }
    }

    int wsk = 0;
    while(wsk < Q.size()){
        auto cur = Q[wsk++];
        int d = dist[cur];
        ans[get<0>(cur)] = min(ans[get<0>(cur)], d);
        ans[get<1>(cur)] = min(ans[get<1>(cur)], d);
        ans[get<2>(cur)] = min(ans[get<2>(cur)], d);
        for(int i=0;i<3;i++){
            for(int j=0;j<3;j++){
                if(i == j) continue;
                int safe[3];
                safe[0] = get<0>(cur);
                safe[1] = get<1>(cur);
                safe[2] = get<2>(cur);
                int moge = min(safe[i], mx[j] - safe[j]);
                safe[j] += moge;
                safe[i] -= moge;
                tuple<int, int, int> state = make_tuple(safe[0], safe[1], safe[2]);
                if(dist[state] == 0 && state != ini){
                    dist[state] = d + 1;
                    Q.pb(state);
                }
            }
        }
    }
    for(int i=1;i<=mx[2]+1;i++){
        int cur = ans[i - 1];
        if(cur == 1e9) cur = -1;
        cout << cur << " ";
    }
}

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

    int tt = 1;
    // cin >> tt;
    while(tt--) solve();

    return 0;
}