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

const int N = 1e6 + 5;

#define st first
#define nd second.first
#define rd second.second

typedef pair<int,int> pun;
typedef long long ll;


int inf =  1<<28;

int A, B, C;
vector<int> v;
int left_n;

typedef pair<int,pair<int,int>> tri;

map<tri, int> mem;
queue<tri> que;

void ch(int a, int x) {
	if (v[a] == inf) left_n --;
	v[a] = min(v[a], x);
}

vector<tri> generate(int a, int b, int c) {
	vector<tri> res;
	int x = min(A, a + b) - a;
	res.push_back({a + x, {b - x, c}});
	x = min(A, a + c) - a;
	res.push_back({a + x, {b, c - x}});
	x = min(B, a + b) - b;
	res.push_back({a - x, {b + x, c}});
	x = min(B, b + c) - b;
	res.push_back({a, {b + x, c - x}});
	x = min(C, a + c) - c;
	res.push_back({a - x, {b, c + x}});
	x = min(C, b + c) - c;
	res.push_back({a, {b - x, c + x}});
	return res;
}

void solve(int a, int b, int c) {
	que.push({a, {b, c}});
	left_n = C + 1;
	while (!que.empty() && left_n > 0) {
		a = que.front().st;
		b = que.front().nd;
		c = que.front().rd;
		int x = mem[que.front()];
		ch(a, x);
		ch(b, x);
		ch(c, x);
		que.pop();
		vector<tri> moves = generate(a, b, c);
		for (auto t : moves) {
			if (mem.count(t) == 0) {
				mem[t] = x + 1;
				que.push(t);
			}
		}
	}
}

int main() {
	int a, b, c;
	cin >> A >> B >> C >> a >> b >> c;
	v.resize(C+1, inf);
	solve(a, b, c);
	for (int x : v) {
		cout << (x == inf ? -1 : x) << " ";
	}
}