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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include <stdio.h>
#include <vector>
#include <map>
#include <unordered_set>
#include <queue>
#include <set>
#include <unordered_map>
#include <math.h>
#include <limits.h>
#include <algorithm>
#include <functional>
#include <iterator>
#include <algorithm>
#include <string>
#include <iostream>

using namespace std;

#define pb push_back
#define mp make_pair

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

struct S {
  int a, b, c;
  int it;
    
  bool operator<(const S& rhs)
  {
      return std::tie(a, b, c) < std::tie(rhs.a, rhs.b, rhs.c);
  }
};

struct scomp {
  bool operator() (const S& lhs, const S& rhs) const {
    return std::tie(lhs.a, lhs.b, lhs.c) < std::tie(rhs.a, rhs.b, rhs.c);
  }
};


int answer[100001];

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

  int A, B, C, ai, bi, ci;

  cin >> A >> B >> C;

  cin >> ai >> bi >> ci;

  for (int i=0; i<=C; ++i) answer[i] = -1;

  set<S, scomp> visited;
  
  queue<S> q;
  q.push({ai, bi, ci, 0});

  while (!q.empty()) {
    S e = q.front();
    q.pop();

    int a=e.a, b=e.b, c=e.c, it=e.it;
    //cout << "CHECKING " << a << ":" << b << ":" << c << " : " << it << endl;

    answer[a] = answer[a] == -1 ? it : min(it, answer[a]);
    answer[b] = answer[b] == -1 ? it : min(it, answer[b]);
    answer[c] = answer[c] == -1 ? it : min(it, answer[c]);

    visited.insert(e);

    vector<S> props;
    if (a < A) {
      int take_max = A - a;
      // do A z B
      if (b > 0) {
        int flow = min(take_max, b);
        props.pb({a+flow, b-flow, c, it+1});
      }
      // do A z C
      if (c > 0) {
        int flow = min(take_max, c);
        props.pb({a+flow, b, c-flow, it+1});
      }
    }

    if (b < B) {
      int take_max = B - b;
      // do B z A
      if (a > 0) {
        int flow = min(take_max, a);
        props.pb({a-flow, b+flow, c, it+1});
      }
      // do B z C
      if (c > 0) {
        int flow = min(take_max, c);
        props.pb({a, b+flow, c-flow, it+1});
      }
    }

    if (c < C) {
      int take_max = C - c;
      // do C z A
      if (a > 0) {
        int flow = min(take_max, a);
        props.pb({a-flow, b, c+flow, it+1});
      }
      // do C z B
      if (b > 0) {
        int flow = min(take_max, b);
        props.pb({a, b-flow, c+flow, it+1});
      }
    }

    for (S p: props) {
      //cout << "check " << p.a << ":" << p.b << ":" << p.c << " : " << p.it << endl;
      if (visited.find(p) == visited.end()) {
        q.push(p);
        visited.insert(p);
      }
    }
  }

  for (int i=0; i<=C; ++i) {
    cout << answer[i] << " ";
  }
  cout << endl;

  return 0;
}