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
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef double K;
constexpr int INF = 0x3f3f3f3f;

#define FOR(i, b, e) for(int i = (b); i < (e); i++)
#define TRAV(x, a) for(auto &x: (a))
#define SZ(x) ((int)(x).size())
#define PB push_back
#define X first
#define Y second


void solve() {
	int lim[3], a, b, c;
	cin >> lim[0] >> lim[1] >> lim[2] >> a >> b >> c;
	map<vi, int> dist;
	queue<vi> q;
	vi ans(lim[2] + 1, -1);
	dist[{a, b, c}] = 0;
	q.push({a, b, c});
	while(!q.empty()) {
		auto v = q.front();
		q.pop();
		FOR(i, 0, 3) if(ans[v[i]] == -1) ans[v[i]] = dist[v];
		FOR(i, 0, 3) FOR(j, 0, 3) {
			if(i == j) continue;
			int ile = min(v[i], lim[j] - v[j]);
			vi nowy = v;
			nowy[i] -= ile, nowy[j] += ile;
			if(!dist.count(nowy)) {
				dist[nowy] = dist[v] + 1;
				q.push(nowy);
			}
		}
	}
	TRAV(x, ans) cout << x << ' ';
	cout << '\n';
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	// int tt; cin >> tt;
	// FOR(te, 0, tt) {
	// 	// cout << "Case #" << te + 1 << ": ";
	// 	solve();
	// }
	solve();
	return 0;
}