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
#include <iostream>
#include <unordered_set>
#include <queue>
#include <algorithm>

using namespace std;
typedef long long ll;

#define MAX 100100
#define BIG 1100100100

#define D(x)

unordered_set<ll> used;
int res[MAX], ww = 0;

struct But {
    int a,b,c;
    int op;
};


queue<But> bb;

void add(But b) {
    ll h = (ll(b.a)<<17) | (ll(b.a)<<34) | ll(b.c);
    auto it = used.find(h);
    if(it == used.end()) {
        used.insert(h);
        bb.push(b);
        D(cout << "added: " << b.a << "," << b.b << "," << b.c  << " op:" << b.op << " ww:" << ww << "\n");
        if(res[b.a] > b.op) { res[b.a] = b.op; ww++;}
        if(res[b.b] > b.op) { res[b.b] = b.op; ww++;}
        if(res[b.c] > b.op) { res[b.c] = b.op; ww++;}
    }
}

void pour(int &x, int X, int &y, int Y, int &op) {
    int v = min(Y-y, x);
    x-=v;
    y+=v;
    op++;
}

int main() {
    int A,B,C,a,b,c;
    cin >> A >> B >> C >> a >> b >> c;
    for(int i=0;i<=C+1;i++) res[i] = BIG;


    add(But{a,b,c,0});
    while(!bb.empty()) {
        But b = bb.front();
        bb.pop();
        {
            But n = b;
            pour(n.a,A,n.b,B, n.op);
            add(n);
        }
        {
            But n = b;
            pour(n.a,A,n.c,C, n.op);
            add(n);
        }

        {
            But n = b;
            pour(n.b,B,n.a,A, n.op);
            add(n);
        }
        {
            But n = b;
            pour(n.b,B,n.c,C, n.op);
            add(n);
        }

        {
            But n = b;
            pour(n.c,C,n.a,A, n.op);
            add(n);
        }
        {
            But n = b;
            pour(n.c,C,n.b,B, n.op);
            add(n);
        }
    }
    for(int i=0;i<C+1;i++) printf("%d ", res[i] < BIG? res[i]: -1);
    printf("\n");

}