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
#include <iostream>
#include <vector>
#include <set>
#include <queue>

using namespace std;


struct State {
    int a, b, c;
    bool operator<(const State& other) const {
        if(a == other.a && b == other.b) return c < other.c;
        if(a == other.a) return b < other.b;
        return a < other.a;
    }
    State(int a, int b, int c) : a(a), b(b), c(c) {}
    State() {}
};
struct Queue_state {
    State s;
    int d;
    Queue_state() {}
    Queue_state(State s, int d) : s(s), d(d) {}
};

int A, B, C;
vector<int> res;
set<State> states;
const int INF = 1e9;


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int a, b, c;
    cin>>A>>B>>C>>a>>b>>c;
    res.assign(C + 1, INF);


    State s(a, b, c);
    queue<Queue_state> q;
    q.push(Queue_state(s, 0));
    states.insert(s);

    while(!q.empty()) {
        s = q.front().s;
        int depth = q.front().d;
        q.pop();

        res[s.a] = min(res[s.a], depth);
        res[s.b] = min(res[s.b], depth);
        res[s.c] = min(res[s.c], depth);

        State s1(max(0, s.a - (B - s.b)), min(s.b + s.a, B), s.c);
        State s2(max(0, s.a - (C - s.c)), s.b, min(s.c + s.a, C));
        State s3(s.a, max(0, s.b - (C - s.c)), min(s.c + s.b, C));
        State s4(s.a, min(s.b + s.c, B), max(0, s.c - (B - s.b)));
        State s5(min(s.a + s.c, A), s.b, max(0, s.c - (A - s.a)));
        State s6(min(s.a + s.b, A), max(0, s.b - (A - s.a)), s.c);

        if(states.find(s1) == states.end()) {
            states.insert(s1);
            q.push(Queue_state(s1, depth + 1));
        }
        if(states.find(s2) == states.end()) {
            states.insert(s2);
            q.push(Queue_state(s2, depth + 1));
        }
        if(states.find(s3) == states.end()) {
            states.insert(s3);
            q.push(Queue_state(s3, depth + 1));
        }
        if(states.find(s4) == states.end()) {
            states.insert(s4);
            q.push(Queue_state(s4, depth + 1));
        }
        if(states.find(s5) == states.end()) {
            states.insert(s5);
            q.push(Queue_state(s5, depth + 1));
        }
        if(states.find(s6) == states.end()) {
            states.insert(s6);
            q.push(Queue_state(s6, depth + 1));
        }
    }


    for(int i = 0; i <= C; ++i) {
        if(res[i] == INF) {
            cout<<-1<<' ';
        }else {
            cout<<res[i]<<' ';
        }
    }
}