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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include <bits/stdc++.h>
#define ll long long
#define pii pair <int,int>
#define ppi pair <pii, pii>
#define psi pair <State, int>
#define fi first
#define se second
using namespace std;


template <typename T>
ostream & operator << (ostream &out, const vector <T> &V) {
	if (!V.empty()) {
		out << "{";
		for (auto v : V)
			out << v << ", ";
		out << "\b\b}";			// \b is backspace
	}
	else {
		out << "{}";
	}
	return out;
}

template <class T1, class T2>
ostream & operator << (ostream &out, const pair <T1, T2> &P) {
	out << "{" << P.first << ", " << P.second << "}";
	return out;
}


struct State {
	int a, b, c;
	
	bool operator < (const State& other) const {
		return this->a < other.a || (this->a == other.a && (this->b < other.b || (this->b == other.b && this->c < other.c)));
	}
};


const int MAX = 100005;

int A, B, C;

int Ans[MAX];


void solve_brutal(int a, int b, int c) {
	for (int i = 0; i <= C; i++) {
		Ans[i] = -1;
	}
	int having_answers = 0;
	queue <psi> Q;
	set <State> S;
	Q.push({{a, b, c}, 0});
	S.insert({a, b, c});
	for (int v : {a, b, c}) {
		if (Ans[v] == -1) {
			having_answers++;
			Ans[v] = 0;
		}
	}
	while (having_answers < C+1 && !Q.empty()) {
		auto &f = Q.front();
		Q.pop();
		State& s = f.fi; int t = f.se;
		// cout << t << " | " << s.a << " " << s.b << " " << s.c <<endl;
		
		int a = s.a, b = s.b, c = s.c, diff;
		if (a < A && b > 0) {
			diff = min(A-a, b);
			State cur = {a+diff, b-diff, c};
			if (S.find(cur) == S.end()) {
				Q.push({cur, t+1});
				S.insert(cur);
				for (int v : {cur.a, cur.b}) {
					if (Ans[v] == -1) {
						having_answers++;
						Ans[v] = t+1;
					}
				}
			}
		}
		if (a < A && c > 0) {
			diff = min(A-a, c);
			State cur = {a+diff, b, c-diff};
			if (S.find(cur) == S.end()) {
				Q.push({cur, t+1});
				S.insert(cur);
				for (int v : {cur.a, cur.c}) {
					if (Ans[v] == -1) {
						having_answers++;
						Ans[v] = t+1;
					}
				}
			}
		}
		if (b < B && a > 0) {
			diff = min(B-b, a);
			State cur = {a-diff, b+diff, c};
			if (S.find(cur) == S.end()) {
				Q.push({cur, t+1});
				S.insert(cur);
				for (int v : {cur.a, cur.b}) {
					if (Ans[v] == -1) {
						having_answers++;
						Ans[v] = t+1;
					}
				}
			}
		}
		if (b < B && c > 0) {
			diff = min(B-b, c);
			State cur = {a, b+diff, c-diff};
			if (S.find(cur) == S.end()) {
				Q.push({cur, t+1});
				S.insert(cur);
				for (int v : {cur.b, cur.c}) {
					if (Ans[v] == -1) {
						having_answers++;
						Ans[v] = t+1;
					}
				}
			}
		}
		if (c < C && a > 0) {
			diff = min(C-c, a);
			State cur = {a-diff, b, c+diff};
			if (S.find(cur) == S.end()) {
				Q.push({cur, t+1});
				S.insert(cur);
				for (int v : {cur.a, cur.c}) {
					if (Ans[v] == -1) {
						having_answers++;
						Ans[v] = t+1;
					}
				}
			}
		}
		if (c < C && b > 0) {
			diff = min(C-c, b);
			State cur = {a, b-diff, c+diff};
			if (S.find(cur) == S.end()) {
				Q.push({cur, t+1});
				S.insert(cur);
				for (int v : {cur.b, cur.c}) {
					if (Ans[v] == -1) {
						having_answers++;
						Ans[v] = t+1;
					}
				}
			}
		}
	}
}



int main() 
{
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
		
	cin >> A >> B >> C;
	
	int a, b, c;
	cin >> a >> b >> c;
		
	solve_brutal(a, b, c);
	
	for (int h = 0; h <= C; h++) {
		cout << Ans[h] << " ";
	}
	cout <<endl;
	return 0;
}