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
 92
 93
 94
 95
 96
 97
 98
 99
100
// Patryk Jędrzejczak

#include <bits/stdc++.h>

using namespace std;

#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPR(i, n) for(int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define FORR(i, a, b) for(int i = b - 1; i >= a; --i)
#define EB emplace_back
#define MP make_pair
#define ST first
#define ND second
#define S size
#define RS resize
#define endl '\n'
#define L long long

template<class T> using V = vector<T>;
using PI = pair<int, int>;

int A, B, C;
int sum;
map<PI, int> dist;
V<int> res;

void bfs(int as, int bs) {
  dist[MP(as, bs)] = 0;
  res[as] = res[bs] = res[sum - as - bs] = 0;
  queue<PI> q;
  q.push(MP(as, bs));

  while (!q.empty()) {
    PI w = q.front();
    q.pop();
    int a = w.ST;
    int b = w.ND;
    int c = sum - a - b;

    int a_b = min(a, B - b);
    if (dist.find(MP(a - a_b, b + a_b)) == dist.end()) {
      q.push(MP(a - a_b, b + a_b));
      dist[MP(a - a_b, b + a_b)] = dist[w] + 1;
      res[a - a_b] = min(res[a - a_b], dist[w] + 1);
      res[b + a_b] = min(res[b + a_b], dist[w] + 1);
    }
    int b_a = min(A - a, b);
    if (dist.find(MP(a + b_a, b - b_a)) == dist.end()) {
      q.push(MP(a + b_a, b - b_a));
      dist[MP(a + b_a, b - b_a)] = dist[w] + 1;
      res[a + b_a] = min(res[a + b_a], dist[w] + 1);
      res[b - b_a] = min(res[b - b_a], dist[w] + 1);
    }
    int a_c = min(a, C - c);
    if (dist.find(MP(a - a_c, b)) == dist.end()) {
      q.push(MP(a - a_c, b));
      dist[MP(a - a_c, b)] = dist[w] + 1;
      res[a - a_c] = min(res[a - a_c], dist[w] + 1);
      res[c + a_c] = min(res[c + a_c], dist[w] + 1);
    }
    int c_a = min(A - a, c);
    if (dist.find(MP(a + c_a, b)) == dist.end()) {
      q.push(MP(a + c_a, b));
      dist[MP(a + c_a, b)] = dist[w] + 1;
      res[a + c_a] = min(res[a + c_a], dist[w] + 1);
      res[c - c_a] = min(res[c - c_a], dist[w] + 1);
    }
    int b_c = min(b, C - c);
    if (dist.find(MP(a, b - b_c)) == dist.end()) {
      q.push(MP(a, b - b_c));
      dist[MP(a, b - b_c)] = dist[w] + 1;
      res[b - b_c] = min(res[b - b_c], dist[w] + 1);
      res[c + b_c] = min(res[c + b_c], dist[w] + 1);
    }
    int c_b = min(B - b, c);
    if (dist.find(MP(a, b + c_b)) == dist.end()) {
      q.push(MP(a, b + c_b));
      dist[MP(a, b + c_b)] = dist[w] + 1;
      res[b + c_b] = min(res[b + c_b], dist[w] + 1);
      res[c - c_b] = min(res[c - c_b], dist[w] + 1);
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int a, b, c;
  cin >> A >> B >> C >> a >> b >> c;

  sum = a + b + c;
  res.RS(C + 1, 1e9);

  bfs(a, b);
  REP(i, C + 1) {
    cout << (res[i] == 1e9 ? -1 : res[i]) << ' ';
  }
}