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
69
70
71
72
73
74
#include <algorithm>
#include <cstdio>
#include <vector>
#include <set>
#include <queue>
#include <climits>

using namespace std;

long r[100002];
long A, B, C, a, b, c, n;
set<long long> v;
queue<long> qa;
queue<long> qb;
queue<long> qc;

void foo(long a, long b, long c)
{
	qa.push(a);
	qb.push(b);
	qc.push(c);
}

void bar()
{
	a = qa.front(); qa.pop();
	b = qb.front(); qb.pop();
	c = qc.front(); qc.pop();
	if (v.count(1000000ll * a + b))
		return;
	v.insert(1000000ll * a + b);
	if (n < r[a]) r[a] = n;
	if (n < r[b]) r[b] = n;
	if (n < r[c]) r[c] = n;
	
	long d = min(B - b, a);
	foo(a - d, b + d, c);
	d = min(C - c, a);
	foo(a - d, b, c + d);

	d = min(A - a, b);
	foo(a + d, b - d, c);
	d = min(C - c, b);
	foo(a, b - d, c + d);

	d = min(A - a, c);
	foo(a + d, b, c - d);
	d = min(B - b, c);
	foo(a, b + d, c - d);
}

int main()
{
	scanf("%ld %ld %ld %ld %ld %ld", &A, &B, &C, &a, &b, &c);
	for (long i = 0; i <= C; ++i)
	{
		r[i] = LONG_MAX;
	}
	foo(a, b, c);
	while (qa.size() > 0)
	{
		for (long i = qa.size(); i > 0; --i)
		{
			bar();
		}
		n++;
	}

	for (long i = 0; i <= C; ++i)
	{
		printf("%ld ", r[i] == LONG_MAX ? -1 : r[i]);
	}
	return 0;
}