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
#include <bits/stdc++.h>
#define dbg(...) fprintf(stderr,__VA_ARGS__)
#define in insert
#define ss second
#define sz size()
#define cn count
#define ff first

using namespace std;

int pour(const vector <int> &s, vector <int> &t, int a, int b) {
	int r=min(t[a],s[b]-t[b]);
	t[a]-=r;
	t[b]+=r;
	return r;
}

void upd(vector <int> &w, const vector <int> &t, int n) {
	for (int i=0; i<3; i++)
		if (w[t[i]] == -1 || n < w[t[i]])
			w[t[i]] = n;
}

int main() {
	vector <int> s(3);
	scanf("%d %d %d",&s[0],&s[1],&s[2]);

	vector <int> t(3);
	scanf("%d %d %d",&t[0],&t[1],&t[2]);

	set <vector<int>> v;
	queue <pair<vector<int>,int>> q;
	vector <int> w(s[2]+1,-1);

	q.push({t,0});

	while (!q.empty()) {

		int n=q.front().ss;
		vector <int> t = q.front().ff;
		q.pop();

		upd(w,t,n);

		for (pair <int,int> i: (vector<pair<int,int>>){{0,1},{0,2},{1,0},{1,2},{2,0},{2,1}}) {

			int r=pour(s,t,i.ff,i.ss);

			if (r>0) {

				if (!v.cn(t)) {
					q.push({t,n+1});
					v.in(t);
				}

				t[i.ss]-=r;
				t[i.ff]+=r;

			}

		}

	}

	

	for (int i: w) printf("%d ",i);
	printf("\n");

	return 0;
}