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
#include <bits/stdc++.h>
using namespace std;
void imax(int &a, int b){
	a=max(a, b);
}
void imin(int &a, int b){
	a=min(a, b);
}
void lmax(long long &a, long long b){
	a=max(a, b);
}
void lmin(long long &a, long long b){
	a=min(a, b);
}
/*
	WARNING: I'm using strange bracket style!
*/
#define triple pair <pair <int, int>, int>
#define aa first.first
#define bb first.second
#define cc second
const int SIZE=1000000;
const int INF=10000000;
int A, B, C, a, b, c, TT;
map <triple, int> M;
set <triple> visited;
queue <triple> Q;
int ans[SIZE];
void push(triple x, int dist){
	if (!M.count(x)) Q.push(x), M[x]=dist+1;	
}
int main()
	{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>A>>B>>C>>a>>b>>c, Q.push({{a, b}, c}), M[{{a, b}, c}]=0;
	while (!Q.empty())
		{
		auto u=Q.front();
		Q.pop();
		if (visited.count(u))
			continue;
		visited.insert(u);
		if (u.aa!=0 && u.bb!=B)		TT=min(u.aa, B-u.bb), push({{u.aa-TT, u.bb+TT}, u.cc}, M[u]);
		if (u.aa!=0 && u.cc!=C)		TT=min(u.aa, C-u.cc), push({{u.aa-TT, u.bb}, u.cc+TT}, M[u]);

		if (u.bb!=0 && u.aa!=A)		TT=min(u.bb, A-u.aa), push({{u.aa+TT, u.bb-TT}, u.cc}, M[u]);
		if (u.bb!=0 && u.cc!=C)		TT=min(u.bb, C-u.cc), push({{u.aa, u.bb-TT}, u.cc+TT}, M[u]);

		if (u.cc!=0 && u.aa!=A)		TT=min(u.cc, A-u.aa), push({{u.aa+TT, u.bb}, u.cc-TT}, M[u]);
		if (u.cc!=0 && u.bb!=B)		TT=min(u.cc, B-u.bb), push({{u.aa, u.bb+TT}, u.cc-TT}, M[u]);
		}
	for (int i=0; i<=C; i++)
		ans[i]=INF;
	for (auto [u, dist]: M)
		imin(ans[u.aa], dist), imin(ans[u.bb], dist), imin(ans[u.cc], dist);
	for (int i=0; i<=C; i++)
		cout<<((ans[i]==INF)?-1:ans[i])<<" ";
	cout<<"\n";
	return 0;
	}