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 <bits/stdc++.h>
using namespace std;

using ll = long long;

const int inf = 1e9;

struct triple {
   int a;
   int b;
   int c;

   bool operator==(triple const& rhs) const {
     return a == rhs.a && b == rhs.b && c == rhs.c;
   }
};

template<>
struct std::hash<triple> {
  unsigned operator()(triple const& t) const {
    return std::hash<ll>()(((ll)t.a << 34) | ((ll)t.b << 17) | t.c);
  }
};

int main() {
  int A, B, C, a, b, c;
  scanf("%d %d %d %d %d %d", &A, &B, &C, &a, &b, &c);
  unordered_map<triple, int> dist;
  dist[{a, b, c}] = 0;
  vector<int> res(C+1, inf);
  deque<triple> Q;
  Q.push_back({a, b, c});
  auto put = [&dist, &Q](int aa, int bb, int cc, int d) {
    triple t{aa, bb, cc};
    if (dist.find(t) == dist.end()) {
      dist[t] = d + 1;
      Q.push_back({aa, bb, cc});
    }
  };
  while (!Q.empty()) {
    auto t = Q.front();
    Q.pop_front();
    int d = dist[t];
    a = t.a, b = t.b, c = t.c;
    res[a] = min(res[a], d);
    res[b] = min(res[b], d);
    res[c] = min(res[c], d);
    if (a) {
      if (b < B) {
        int diff = min(a, B-b);
        put(a - diff, b + diff, c, d);
      }
      if (c < C) {
        int diff = min(a, C-c);
        put(a - diff, b, c + diff, d);
      }
    }
    if (b) {
      if (a < A) {
        int diff = min(b, A-a);
        put(a + diff, b - diff, c, d);
      }
      if (c < C) {
        int diff = min(b, C-c);
        put(a, b - diff, c + diff, d);
      }
    }
    if (c) {
      if (a < A) {
        int diff = min(c, A-a);
        put(a + diff, b, c - diff, d);
      }
      if (b < B) {
        int diff = min(c, B-b);
        put(a, b + diff, c - diff, d);
      }
    }
  }
  for (int i : res) {
    printf("%d ", i == inf ? -1 : i);
  }
  printf("\n");
}