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

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SZ(a) ((int)(a).size())
#define ALL(a) (a).begin(), (a).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

constexpr int kInf = 1000 * 1000 * 1000 + 7;
constexpr int kMod = 1000 * 1000 * 1000 + 7;
constexpr long long kInfLL = 1e18;

int A[3];

struct State {
  int a[3];

  vector<State> Nei() {
    vector<State> result;
    REP(i, 3) REP(j, 3) if (i != j) {
      State nei = {{a[0], a[1], a[2]}};
      int amount = min(nei.a[i], A[j] - nei.a[j]);
      nei.a[i] -= amount;
      nei.a[j] += amount;
      result.push_back(nei);
    }
    return result;
  }

  friend bool operator <(const State& a, const State& b) {
    return make_tuple(a.a[0], a.a[1], a.a[2]) < make_tuple(b.a[0], b.a[1], b.a[2]);
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  REP(i, 3) cin >> A[i];

  State s;
  REP(i, 3) cin >> s.a[i];

  map<State,int> dist;
  dist[s] = 0;
  queue<State> q;
  q.push(s);
  while (!q.empty()) {
    s = q.front();
    q.pop();
    for (auto nei: s.Nei()) {
      if (dist.count(nei)) {
        continue;
      }
      dist[nei] = dist[s] + 1;
      q.push(nei);
    }
  }

  vector<int> result(A[2] + 1, -1);
  for (const auto& [state, val] : dist) {
    REP(i, 3) {
      if (result[state.a[i]] != -1 && result[state.a[i]] < val) {
        continue;
      }
      result[state.a[i]] = val;
    }
  }

  for (int e: result) cout << e << ' ';
  cout << '\n';
}