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 <cstdio>
#include <unordered_map>
#include <queue>
#include <algorithm>
#define BASE 300010ll
#define INF 1000000000
using namespace std;

unordered_map<long long, int> odl;
queue<pair<int, pair<int, int> >> q;

int wyn[BASE];

long long serialize(long long  a, long long  b, long long  c) {
    return a * BASE * BASE + b * BASE + c;
}

int ac, bc, cc;
int al, bl, cl;
int sumL;

void consider(int A, int B, int C, int o) {
    auto s = serialize(A, B, C);
    if (odl.find(s) == odl.end()) {
        odl.insert(make_pair(s, o));
        q.push(make_pair(A, make_pair(B, C)));
    }
}

int main() {
    scanf("%d%d%d", &ac, &bc, &cc);
    scanf("%d%d%d", &al, &bl, &cl);
    sumL = al + bl + cl;

    for (int i = 0; i <= cc; i++) {
        wyn[i] = INF;
    }

    q.push(make_pair(al, make_pair(bl, cl)));
    odl[serialize(al, bl, cl)] = 0;

    while (!q.empty()) {
        auto x = q.front();
        q.pop();
        int A = x.first;
        int B = x.second.first;
        int C = x.second.second;
        int o = odl[serialize(A, B, C)];
        wyn[A] = min(wyn[A], o);
        wyn[B] = min(wyn[B], o);
        wyn[C] = min(wyn[C], o);

        // A to B
        if (A > bc - B) consider(sumL - bc - C, bc, C, o + 1);
        else consider(0, sumL - C, C, o + 1);

        // A to C
        if (A > cc - C) consider(sumL - cc - B, B, cc, o + 1);
        else consider(0, B, sumL - B, o + 1);

        // B to A
        if (B > ac - A) consider(ac, sumL - ac - C, C, o + 1);
        else consider(sumL - C, 0, C, o + 1);

        // B to C
        if (B > cc - C) consider(A, sumL - cc - A, cc, o + 1);
        else consider(A, 0, sumL - A, o + 1);

        // C to A
        if (C > ac - A) consider(ac, B, sumL - ac - B, o + 1);
        else consider(sumL - B, B, 0, o + 1);

        // C to B
        if (C > bc - B) consider(A, bc, sumL - bc - A, o + 1);
        else consider(A, sumL - A, 0, o + 1);
    }

    for (int i = 0; i <= cc; i++) {
        printf("%d ", wyn[i] == INF ? -1 : wyn[i]);
    }
    printf("\n");

}