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
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define SZ 3234565
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
gp_hash_table<ll,int> id;
vector<int> va[SZ];
int E,d[SZ];
int gid(int p,int q,int r) {
	int&s=id[(p*233333LL+q)*233333LL+r];
	if(!s) s=++E,va[E]={p,q,r};
	return s;
}
int A,B,C,a,b,c,qs[SZ],h=0,t=0;
int ans[SZ];
int main()
{
//	A=1e5-98,B=1e5-97,C=1e5;
//	a=0.5e5,b=0.51e5,c=0.47e5;
	cin>>A>>B>>C>>a>>b>>c;
	int x=gid(a,b,c); d[x]=1;
	qs[t++]=x;
	int mx[]={A,B,C};
	for(int i=0;i<=C;++i) ans[i]=-1;
	while(h!=t) {
		x=qs[h++];
		auto upd=[&](int&a,int b) {
			--b; if(a==-1||a>b) a=b;
		};
		upd(ans[va[x][0]],d[x]);
		upd(ans[va[x][1]],d[x]);
		upd(ans[va[x][2]],d[x]);
		for(int s=0;s<3;++s) {
			for(int t=0;t<3;++t) if(s!=t) {
				int p[]={va[x][0],va[x][1],va[x][2]};
				int dd=min(p[s],mx[t]-p[t]);
				p[s]-=dd; p[t]+=dd;
				int w=gid(p[0],p[1],p[2]);
				if(d[w]) continue;
				d[w]=d[x]+1; qs[::t++]=w;
			}
		}
	}
	for(int i=0;i<=C;++i)
		printf("%d ",ans[i]);
}