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
#include <cstdio>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>

using namespace std;
using tri = pair<pair<int, int>, int>;

#define e1 first.first
#define e2 first.second
#define e3 second
#define pack(a, b, c)  { { a, b }, c }
#define unpack(a, b, c, t)  auto a = t.e1; auto b = t.e2; auto c = t.e3;

#define prop(a, b, c, d) \
  if (D.find(pack(a, b, c)) == D.end()) {  \
    D[pack(a, b, c)] = d;                  \
    Q.push(pack(a, b, c));                 \
  }


int pour(int f, int t, int c) {
  return min(f, c - t);
}


int main() {
  int A, B, C;
  scanf("%d%d%d", &A, &B, &C);
  int a, b, c;
  scanf("%d%d%d", &a, &b, &c);

  queue<tri> Q;
  map<tri, int> D;
  Q.push(pack(a, b, c));
  D[pack(a, b, c)] = 0;

  while (!Q.empty()) {
    unpack(a, b, c, Q.front());
    int d = D[Q.front()] + 1;
    Q.pop();

    int x0 = pour(a, b, B);
    prop(a - x0, b + x0, c, d);

    int x1 = pour(b, a, A);
    prop(a + x1, b - x1, c, d);

    int x2 = pour(a, c, C);
    prop(a - x2, b, c + x2, d);

    int x3 = pour(c, a, A);
    prop(a + x3, b, c - x3, d);

    int x4 = pour(b, c, C);
    prop(a, b - x4, c + x4, d);

    int x5 = pour(c, b, B);
    prop(a, b + x5, c - x5, d);
  }

  vector<int> outs(C + 1);
  for (int i = 0; i <= C; i++) outs[i] = 123456789;

  for (auto [k, v] : D) {
    unpack(a, b, c, k);
    outs[a] = min(outs[a], v);
    outs[b] = min(outs[b], v);
    outs[c] = min(outs[c], v);
  }

  for (int i = 0; i <= C; i++) {
    printf("%d ", outs[i] == 123456789 ? -1 : outs[i]);
  }
  puts("");
}