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
#include<bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair

using namespace std;

constexpr int MAX_C = 100000;

int t[MAX_C];
int P[3], i[3],j[3];
map<pair<pair<int, int>, int>, int> m;
queue<pair<pair<int,int>,int> > q;

pair<pair<int,int>, int> i_k() {
	return mp(mp(i[0],i[1]),i[2]);
}

pair<pair<int,int>, int> j_k() {
	return mp(mp(j[0],j[1]),j[2]);
}

int main() {
	scanf("%d%d%d", &P[0], &P[1], &P[2]);
	
	scanf("%d%d%d", &i[0], &i[1], &i[2]);
	q.push(i_k());
	m[i_k()] = 1;
	
	while(!q.empty()) {
		i[0] = q.front().ff.ff;
		i[1] = q.front().ff.ss;
		i[2] = q.front().ss;
		q.pop();
		int st = m[i_k()];
		for(int h = 0; h < 3; ++h) {
			if(t[i[h]] <= 0) t[i[h]] = st;
			j[h] = i[h];
		}
		for(int h = 0; h < 3; ++h) {
			for(int g = 0; g < 3; ++g) {
				if(h != g) {
					int p = min(j[h], P[g] - j[g]);
					
					j[h] -= p;
					j[g] += p;
					if(m[j_k()] <= 0) {
						m[j_k()] = st+1;
						q.push(j_k());
					}
					j[h] = i[h];
					j[g] = i[g];
				}
			}
		}
	}
	
	for(int h = 0; h <= P[2]; ++h) {
		printf("%d ", t[h]-1);
	}
	printf("\n");
}