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
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second

struct but {
	int a, b, c;
};

bool operator<(const but &x, const but &y) {
	if (x.a != y.a)
		return x.a < y.a;
	if (x.b != y.b)
		return x.b < y.b;
	return x.c < y.c;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int maxa, maxb, maxc;
	int starta, startb, startc;
	cin >> maxa >> maxb >> maxc;
	cin >> starta >> startb >> startc;
	vector <int> res(maxc + 1, INT_MAX);
	deque <pair <but, int> > q;
	set <but> s;
	but start = {starta, startb, startc};
	q.emplace_back(make_pair(start, 0));
	s.insert(start);
	while (!q.empty()) {
		but cur = q.front().ff;
		int wyn = q.front().ss;
		q.pop_front();
		int a = cur.a, b = cur.b, c = cur.c;
		res[a] = min(res[a], wyn);
		res[b] = min(res[b], wyn);
		res[c] = min(res[c], wyn);
		if (a < maxa) {
			// b -> a
			int d = (maxa - a >= b) ? b : maxa - a;
			but temp = {a + d, b - d, c};
			if (s.find(temp) == s.end()) {
				q.emplace_back(make_pair(temp, wyn + 1));
				s.insert(temp);
			}
			// c -> a
			d = (maxa - a >= c) ? c : maxa - a;
			temp = {a + d, b, c - d};
			if (s.find(temp) == s.end()) {
				q.emplace_back(make_pair(temp, wyn + 1));
				s.insert(temp);
			}
		}
		if (b < maxb) {
			// a -> b
			int d = (maxb - b >= a) ? a : maxb - b;
			but temp = {a - d, b + d, c};
			if (s.find(temp) == s.end()) {
				q.emplace_back(make_pair(temp, wyn + 1));
				s.insert(temp);
			}
			// c -> b
			d = (maxb - b >= c) ? c : maxb - b;
			temp = {a, b + d, c - d};
			if (s.find(temp) == s.end()) {
				q.emplace_back(make_pair(temp, wyn + 1));
				s.insert(temp);
			}
		}
		if (c < maxc) {
			// a -> c
			int d = (maxc - c >= a) ? a : maxc - c;
			but temp = {a - d, b, c + d};
			if (s.find(temp) == s.end()) {
				q.emplace_back(make_pair(temp, wyn + 1));
				s.insert(temp);
			}
			// b -> c
			d = (maxc - c >= b) ? b : maxc - c;
			temp = {a, b - d, c + d};
			if (s.find(temp) == s.end()) {
				q.emplace_back(make_pair(temp, wyn + 1));
				s.insert(temp);
			}
		}
		/*
		for (auto i : q)
			cerr << i.ff.a << " "<< i.ff.b << " " << i.ff.c << " " << i.ss << "\n";;
		cerr << "\n";
		*/
	}
	for (auto i : res) {
		if (i != INT_MAX)
			cout << i << " ";
		else
			cout << "-1 ";
	}
	cout << "\n";
	return 0;
}