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
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

constexpr int M = 1e5+7;
constexpr int oo = 1e9+7;
constexpr long long m1 = 1e12;
constexpr long long m2 = 1e6;

int o[M];
int A, B, C;
unordered_map<long long, bool>mapa;
queue<pair<pair<int,int>,pair<int,int> > >Q;

void backtrack(int a, int b, int c){
	int steps, a1, b1, c1;
	Q.push({{a, b}, {c, 0}});

	while(Q.size()){
		a1 = Q.front().first.first;
		b1 = Q.front().first.second;
		c1 = Q.front().second.first;
		steps = Q.front().second.second;
		Q.pop();		
			
		if(mapa[m1*a1 + m2*b1 + c1]) continue;
		mapa[m1*a1 + m2*b1 + c1] = 1;
		o[a1] = min(o[a1], steps);
		o[b1] = min(o[b1], steps);
		o[c1] = min(o[c1], steps);
		
		if(B-b1 >= a1) Q.push({{0, b1+a1}, {c1, steps+1}});
		else Q.push({{a1 - (B-b1), B}, {c1, steps+1}});
		
		if(C-c1 >= a1) Q.push({{0, b1}, {c1+a1, steps+1}});
		else Q.push({{a1 - (C-c1), b1}, {C, steps+1}});
		
		if(A-a1 >= b1) Q.push({{a1+b1, 0}, {c1, steps+1}});
		else Q.push({{A, b1 - (A-a1)}, {c1, steps+1}});
		
		if(C-c1 >= b1) Q.push({{a1, 0}, {c1+b1, steps+1}});
		else Q.push({{a1, b1 - (C-c1)}, {C, steps+1}});
	
		if(A-a1 >= c1) Q.push({{a1+c1, b1}, {0, steps+1}});
		else Q.push({{A, b1}, {c1 - (A-a1), steps+1}});
	
		if(B-b1 >= c1) Q.push({{a1, b1+c1}, {0, steps+1}});
		else Q.push({{a1, B}, {c1 - (B-b1), steps+1}});
	}
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int a, b, c;
	
	cin >> A >> B >> C >> a >> b >> c;
	for(int i=0; i<=C; i++) o[i] = oo;
	
	backtrack(a, b, c);
	
	for(int i=0; i<=C; i++) cout << (o[i] == oo ? -1 : o[i]) << ' ';
	
	return 0;
}