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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include <random>
#include <chrono>
#include <ctime>
#include<list>
#include <numeric>
#include<bitset>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<utility>
#include<fstream>
#include<sstream>
#include<cmath>
#include<stack>
#include<assert.h>
#include<unordered_map>
#include<unordered_set>
#include <array>
#include <complex>
#include<iomanip>
using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(int i = 0; i < n; i++)
#define FORAB(i, a, b) for(int i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))
#define AIN(A, B, C) assert(IN(A, B, C))

typedef long long int LL;
//typedef __int128 LLL;
typedef long long LLL;

typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<LL, int> PLI;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PLL> VPL;
typedef vector<PII> VP;
typedef vector<double> VD;
typedef vector<vector<int>> VVI;
typedef vector<string> VS;
typedef long double ld;
typedef unsigned long long ULL;

//#define MAXN 1000
//#define MAXN2 MAXN*MAXN
#define MAXN 100

//const LL MOD[2] = { 87420317, 1000000007 };
//const LL MOD = 1000000007;
const LL MOD = 998244353;
//const LL MOD = 547892069;
//const LL INF = 2000000000000000001LL; //2e18 + 1

int vis[3][2][3][100005];
struct Node {
	int at0;
	int foe;
	int at1;
	int amount;

	VI V;
};

int ans[100005];
int Size[3];
int a, b, c;

Node Pour(VI V, int from, int to) {
	int to_pour = MIN(V[from], Size[to] - V[to]);
	V[from] -= to_pour;
	V[to] += to_pour;
	FORN(i, 3) {
		if (V[i] == 0 || V[i] == Size[i]) {
			Node n;
			n.V = V;
			n.at0 = i;
			n.foe = (V[i] == Size[i]);
			n.at1 = (i == 0 ? 1 : 0);
			AIN(n.at1, 0, 2);
			n.amount = V[n.at1];
			return n;
		}
	}
	assert(0);
}

VI decode(int at0, int foe, int at1, int amount) {
	VI V(3);
	V[at0] = (foe ? Size[at0] : 0);
	V[at1] = amount;
	V[0 + 1 + 2 - at0 - at1] = a + b + c - V[at0] - V[at1];
	return V;
}

int brute[32][32][32];
int bruteAns[32];

void Brute() {
	MEM(brute, -1);
	queue<VI> Q;
	Q.push({ a, b, c });
	brute[a][b][c] = 0;
	auto Update = [&](VI u, int x, int y) {
		int pour = MIN(u[x], Size[y] - u[y]);
		u[x] -= pour;
		u[y] += pour;
		return u;
	};
	while (!Q.empty()) {
		auto u = Q.front();
		Q.pop();
		FORN(x, 3) FORN(y, 3) {
			if (x != y) {
				VI v = Update(u, x, y);
				if (brute[v[0]][v[1]][v[2]] == -1) {
					brute[v[0]][v[1]][v[2]] = brute[u[0]][u[1]][u[2]] + 1;
					Q.push(v);
				}
			}
		}
	}
	MEM(bruteAns, -1);
	FORN(i, Size[2] + 1) FORN(j, Size[2] + 1) FORN(k, Size[2] + 1) {
		if (brute[i][j][k] != -1) {
			if (bruteAns[i] == -1 || bruteAns[i] > brute[i][j][k]) bruteAns[i] = brute[i][j][k];
			if (bruteAns[j] == -1 || bruteAns[j] > brute[i][j][k]) bruteAns[j] = brute[i][j][k];
			if (bruteAns[k] == -1 || bruteAns[k] > brute[i][j][k]) bruteAns[k] = brute[i][j][k];
		}
	}
}

void solve(int ks) {

	scanf("%d %d %d", &Size[0], &Size[1], &Size[2]);
	scanf("%d %d %d", &a, &b, &c);
	MEM(ans, -1);
	MEM(vis, -1);

	//Brute();

	ans[a] = 0;
	ans[b] = 0;
	ans[c] = 0;

	queue<Node> Q;
	FORN(x, 3) FORN(y, 3) if (x != y) {
		VI V = { a, b, c };
		Node n = Pour(V, x, y);
		if (vis[n.at0][n.foe][n.at1][n.amount] != -1) continue;
		vis[n.at0][n.foe][n.at1][n.amount] = 1;
		Q.push(n);
	}
	while (!Q.empty()) {
		Node u = Q.front();
		Q.pop();

		FORN(x, 3) FORN(y, 3) if (x != y) {
			Node n = Pour(u.V, x, y);
			if (vis[n.at0][n.foe][n.at1][n.amount] != -1) continue;
			vis[n.at0][n.foe][n.at1][n.amount] = vis[u.at0][u.foe][u.at1][u.amount] + 1;
			Q.push(n);
		}
	}

	auto UpdateAns = [&](int amount, int d) {
		if (ans[amount] == -1 || ans[amount] > d) ans[amount] = d;
	};

	FORN(at0, 3) FORN(foe, 2) FORN(at1, 3) FORN(amount, Size[2] + 1) {
		int d = vis[at0][foe][at1][amount];
		if (d == -1) continue;
		VI V = decode(at0, foe, at1, amount);
		FORN(i, 3) UpdateAns(V[i], d);
	}
	/*
	FORAB(amount, 0, Size[2]) {
		if (amount) printf(" ");
		printf("%d", bruteAns[amount]);
	}
	printf("\n");
	*/
	FORAB(amount, 0, Size[2]) {
		if (amount) printf(" ");
		printf("%d", ans[amount]);
	}
	printf("\n");
	/*
	FORAB(amount, 0, Size[2]) {
		assert(ans[amount] == bruteAns[amount]);
	}
	*/
}

void gen() {
}

int main()
{
	double start_time = clock();
#ifdef LOCAL
	freopen("C:\\Home\\Contests\\F\\sample.in", "r", stdin);
	//freopen("C:\\Home\\Contests\\F\\0.out", "w", stdout);
#endif

	gen();

	if (0) {
		int T;
		scanf("%d", &T);
		//AIN(T, 1, 10);
		for (int ks = 1; ks <= T; ks++) {
			solve(ks);
			//if (ks % 1 == 0) fprintf(stderr, "%d done\n", ks);
		}
	}
	else {
		solve(1);
	}

	double end_time = clock();
	fprintf(stderr, "Time = %lf\n", (end_time - start_time) / CLOCKS_PER_SEC);
	return 0;
}