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
#define make_pair mp
#define emplace_back pb
#include <bits/stdc++.h>
using namespace std;
mt19937 mt_rand(time(0));
const int N = 1e5 + 5;
int C[3], a, b, c, val[N];
map<int, map<int, int>> m;

struct trip {
    int tab[3];
};

queue<trip> q;

void bfs() {
    for(int i=0;i<=C[2];i++) val[i] = 1e9;
    trip init;
    init.tab[0] = a;
    init.tab[1] = b;
    init.tab[2] = c;
    q.push(init);
    m[a][b] = 1;
    val[a] = 0;
    val[b] = 0;
    val[c] = 0;
    while(!q.empty()) {
        trip t = q.front();
        q.pop();
        int d = m[t.tab[0]][t.tab[1]];

        for(int i=0;i<3;i++)
        for(int j=0;j<3;j++) {
            if(i == j) continue;
            trip next = t;
            if(t.tab[i] <= C[j] - t.tab[j]) {
                next.tab[i] = 0;
                next.tab[j] = t.tab[j] + t.tab[i];
            } else {
                next.tab[j] = C[j];
                next.tab[i] = t.tab[i] - (C[j] - t.tab[j]);
            }
            int x = next.tab[0];
            int y = next.tab[1];
            int z = next.tab[2];
            if(m[x][y] != 0) continue;
            m[x][y] = d + 1;
            q.push(next);
            val[x] = min(val[x], d);
            val[y] = min(val[y], d);
            val[z] = min(val[z], d);
        }
    }
}

int main() {
	scanf("%d%d%d", &C[0], &C[1], &C[2]);
    scanf("%d%d%d", &a, &b, &c);
    bfs();
    for(int i=0;i<=C[2];i++) {
        if(val[i] == 1e9) printf("-1 ");
        else printf("%d ", val[i]);
    }
	return 0;
}