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
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef pair <ii,int> iii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;
const int N = 100005;

int tab[3], maxx[3], i, j, k, bat[3], mat[3], newV, res[N];
map<iii, int> mapa;
iii v, v2;
queue<iii> q;

int main() {
/*int ma = 0;
int LIM = 10;
for (int A=0;A<=LIM;A++) for (int B=A;B<=LIM;B++) for (int C=B;C<=LIM;C++) for (int a=0;a<=A;a++) for (int b=0;b<=B;b++) for (int c=0;c<=C;c++) {
	maxx[0] = A;
	maxx[1] = B;
	maxx[2] = C;
	tab[0] = a;
	tab[1] = b;
	tab[2] = c;
	s.clear();
	for (i=0;i<=maxx[2];i++) res[i] = INF;
	go(0);
	if (s.size() > ma) {
		ma = s.size();
		printf("%d : %d %d %d %d %d %d\n", ma, A, B, C, a, b, c);
	}
}*/

for (i=0;i<3;i++) scanf("%d", &maxx[i]);
for (i=0;i<3;i++) scanf("%d", &tab[i]);
for (i=0;i<=maxx[2];i++) res[i] = INF;
for (i=0;i<3;i++) res[tab[i]] = 0;
mapa.clear();
mapa[iii(ii(tab[0], tab[1]), tab[2])] = 0;
while(!q.empty()) q.pop();
q.push(iii(ii(tab[0], tab[1]), tab[2]));
while (!q.empty()) {
	v = q.front();
	q.pop();
	bat[0] = v.first.first;
	bat[1] = v.first.second;
	bat[2] = v.second;
	for (i=0;i<3;i++) if (bat[i] < maxx[i]) {
		for (j=0;j<3;j++) if (i != j && bat[j] > 0) {
			int mov = min(maxx[i] - bat[i], bat[j]);
			for (k=0;k<3;k++) mat[k] = bat[k];
			mat[i] += mov;
			mat[j] -= mov;
			v2 = iii(ii(mat[0], mat[1]), mat[2]);
			if (mapa.find(v2) != mapa.end()) continue;
			newV = mapa[v] + 1;
			mapa[v2] = newV;
			q.push(v2);			
			for (k=0;k<3;k++) res[mat[k]] = min(res[mat[k]], newV);
		}
	}
}
for (i=0;i<=maxx[2];i++) if (res[i] == INF) printf("-1 "); else printf("%d ", res[i]);
printf("\n");
//printf("%d\n", s.size());
return 0;
}