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
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <time.h>
#include <queue>

using namespace std;

typedef pair<int, pair<int, int> > config_t;

int main () {
	int A, B, C, aa, bb, cc;
	scanf("%d %d %d\n%d %d %d", &A, &B, &C, &aa, &bb, &cc);
	vector<int> res(C + 7, -1);
	set<config_t> configs;
	configs.insert(make_pair(aa, make_pair(bb, cc)));
	queue<pair<int, config_t> > q;
	q.push(make_pair(0, make_pair(aa, make_pair(bb, cc))));
	while (!q.empty()) {
		pair<int, config_t> item = q.front();
		q.pop();
		int t = item.first;
		int a = item.second.first;
		int b = item.second.second.first;
		int c = item.second.second.second;	
//		printf("POP %d %d %d %d\n", t, a, b, c);
		if (res[a] == -1) {
			res[a] = t;
		}
		if (res[b] == -1) {
			res[b] = t;
		}
		if (res[c] == -1) {
			res[c] = t;
		}
		vector<config_t> cases;
		cases.push_back(make_pair(a - min(a, B - b), make_pair(b + min(a, B - b), c)));
		cases.push_back(make_pair(a + min(b, A - a), make_pair(b - min(b, A - a), c)));
		cases.push_back(make_pair(a - min(a, C - c), make_pair(b, c + min(a, C - c))));
		cases.push_back(make_pair(a + min(c, A - a), make_pair(b, c - min(c, A - a))));
		cases.push_back(make_pair(a, make_pair(b - min(b, C - c), c + min(b, C - c))));
		cases.push_back(make_pair(a, make_pair(b + min(c, B - b), c - min(c, B - b))));
		for (int i = 0; i < 6; ++i) {
			if (configs.find(cases[i]) != configs.end()) {
				continue;
			}
			configs.insert(cases[i]);
			q.push(make_pair(t + 1, cases[i]));
		}
	}
	for (int i = 0; i < C + 1; ++i) {
		printf("%d", res[i]);
		if (i < C) {
			printf(" ");
		}
	}
	printf("\n");
	return 0;
}