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
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=1e5+7, INF=1e9+7;
int ans[LIM];
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int A, B, C;
	cin >> A >> B >> C;
	rep(i, C+1) ans[i]=INF;
	int a, b, c;
	cin >> a >> b >> c;
	map<pair<int,pair<int,int>>,int>mp;
	priority_queue<pair<int,pair<int,pair<int,int>>>>q;
	q.push({-1, {a, {b, c}}});
	while(!q.empty()) {
		auto p=q.top(); q.pop();
		p.st*=-1;
		if(mp[p.nd]) continue;
		mp[p.nd]=p.st;
		ans[p.nd.st]=min(ans[p.nd.st], p.st-1);
		ans[p.nd.nd.st]=min(ans[p.nd.nd.st], p.st-1);
		ans[p.nd.nd.nd]=min(ans[p.nd.nd.nd], p.st-1);
		a=p.nd.st;
		b=p.nd.nd.st;
		c=p.nd.nd.nd;
		if(!mp[{a-min(a, B-b), {b+min(a, B-b), c}}]) {
			q.push({-p.st-1, {a-min(a, B-b), {b+min(a, B-b), c}}});
		}
		if(!mp[{a-min(a, C-c), {b, c+min(a, C-c)}}]) {
			q.push({-p.st-1, {a-min(a, C-c), {b, c+min(a, C-c)}}});
		}
		if(!mp[{a+min(b, A-a), {b-min(b, A-a), c}}]) {
			q.push({-p.st-1, {a+min(b, A-a), {b-min(b, A-a), c}}});
		}
		if(!mp[{a, {b-min(b, C-c), c+min(b, C-c)}}]) {
			q.push({-p.st-1, {a, {b-min(b, C-c), c+min(b, C-c)}}});
		}
		if(!mp[{a+min(c, A-a), {b, c-min(c, A-a)}}]) {
			q.push({-p.st-1, {a+min(c, A-a), {b, c-min(c, A-a)}}});
		}
		if(!mp[{a, {b+min(c, B-b), c-min(c, B-b)}}]) {
			q.push({-p.st-1, {a, {b+min(c, B-b), c-min(c, B-b)}}});
		}
	}
	rep(i, C+1) cout << (ans[i]==INF?-1:ans[i]) << " ";
	cout << '\n';
}