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

const int N = 1e5 + 5;
int wyn[N];

bool odwa[N];
bool odwb[N];
bool odwc[N];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int A, B, C, a, b, c;
	cin >> A >> B >> C >> a >> b >> c;
	
	for(int i = 0; i <= C; i++) wyn[i] = -1;
	
	wyn[a] = 0;
	wyn[b] = 0;
	wyn[c] = 0;
	
	odwa[a] = 1;
	odwb[b] = 1;
	odwc[c] = 1;
	
	priority_queue <pair <pair <int, int>, pair <int, int> > > q;
	
	if(a != 0 && a <= B - b) q.push(make_pair(make_pair(-1, 0), make_pair(a + b, c)));
	else if(a != 0 && b != B) q.push(make_pair(make_pair(-1, a + b - B), make_pair(B, c)));
	
	if(a != 0 && a <= C - c) q.push(make_pair(make_pair(-1, 0), make_pair(b, a + c)));
	else if(a != 0 && c != C) q.push(make_pair(make_pair(-1, a + c - C), make_pair(b, C)));
	
	if(b != 0 && b <= A - a) q.push(make_pair(make_pair(-1, a + b), make_pair(0, c)));
	else if(b != 0 && a != A) q.push(make_pair(make_pair(-1, A), make_pair(a + b - A, c)));
	
	if(b != 0 && b <= C - c) q.push(make_pair(make_pair(-1, a), make_pair(0, b + c)));
	else if(b != 0 && c != C) q.push(make_pair(make_pair(-1, a), make_pair(b + c - C, C)));
	
	if(c != 0 && c <= A - a) q.push(make_pair(make_pair(-1, a + c), make_pair(b, 0)));
	else if(c != 0 && a != A) q.push(make_pair(make_pair(-1, A), make_pair(b, a + c - A)));
	
	if(c != 0 && c <= B - b) q.push(make_pair(make_pair(-1, a), make_pair(b + c, 0)));
	else if(c != 0 && b != B) q.push(make_pair(make_pair(-1, a), make_pair(B, b + c - B)));
	
	while(!q.empty()){
		int a1 = q.top().first.second;
		int b1 = q.top().second.first;
		int c1 = q.top().second.second;
		int val = -q.top().first.first;
		q.pop();
		
		//cout << a1 << " " << b1 << " " << c1 << " " << val << "\n";
		
		if(odwa[a1] && odwb[b1] && odwc[c1]) continue;
		
		odwa[a1] = 1;
		odwb[b1] = 1;
		odwc[c1] = 1;
		
		if(wyn[a1] != -1) wyn[a1] = min(wyn[a1], val);
		else wyn[a1] = val;
		
		if(wyn[b1] != -1) wyn[b1] = min(wyn[b1], val);
		else wyn[b1] = val;
		
		if(wyn[c1] != -1) wyn[c1] = min(wyn[c1], val);
		else wyn[c1] = val;
		
		if(a1 != 0 && a <= B - b1) q.push(make_pair(make_pair(-val - 1,0), make_pair(a1 + b1, c1)));
		else if(a1 != 0 && b1 != B) q.push(make_pair(make_pair(-val-1, a1 + b1 - B), make_pair(B, c1)));
		
		if(a1 != 0 && a1 <= C - c1) q.push(make_pair(make_pair(-val-1, 0), make_pair(b1, a1 + c1)));
		else if(a1 != 0 && c1 != C) q.push(make_pair(make_pair(-val-1, a1 + c1 - C), make_pair(b1, C)));
		
		if(b1 != 0 && b1 <= A - a1) q.push(make_pair(make_pair(-val-1, a1 + b1), make_pair(0, c1)));
		else if(b1 != 0 && a1 != A) q.push(make_pair(make_pair(-val-1, A), make_pair(a1 + b1 - A, c1)));
		
		if(b1 != 0 && b1 <= C - c1) q.push(make_pair(make_pair(-val-1, a1), make_pair(0, b1 + c1)));
		else if(b1 != 0 && c1 != C) q.push(make_pair(make_pair(-val-1, a1), make_pair(b1 + c1 - C, C)));
		
		if(c1 != 0 && c1 <= A - a1) q.push(make_pair(make_pair(-val-1, a1 + c1), make_pair(b1, 0)));
		else if(c1 != 0 && a1 != A) q.push(make_pair(make_pair(-val-1, A), make_pair(b1, a1 + c1 - A)));
		
		if(c1 != 0 && c1 <= B - b1) q.push(make_pair(make_pair(-val-1, a1), make_pair(b1 + c1, 0)));
		else if(c1 != 0 && b1 != B) q.push(make_pair(make_pair(-val-1, a1), make_pair(B, b1 + c1 - B)));
	}
	
	for(int i = 0; i <= C; i++) cout << wyn[i] << " ";
}