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
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;
const int G = 5;

int space[3];
int dis[N];
bitset<N> odw[3][2];

void make_move(vector<int> &state, int gleb, queue<pair<vector<int>, int> > &order) {
	for (int v : state) {
		if (dis[v] == 0 || dis[v] > gleb) {
			dis[v] = gleb;
		}
	}
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			if (i == j) {
				continue;
			}
			vector<int> new_state(state);
			int ile = min(space[j] - state[j], state[i]);
			new_state[j] += ile;
			new_state[i] -= ile;
			if (ile == state[i]) {
				int nr = 2;
				if (i == 2) {
					nr--;
				}
				if (!odw[i][0][new_state[nr]]) {
					order.push(make_pair(new_state, gleb + 1));
					odw[i][0][new_state[nr]] = true;
				}
			}
			else {
				int nr = 2;
				if (j == 2) {
					nr--;
				}
				if (!odw[j][1][new_state[nr]]) {
					order.push(make_pair(new_state, gleb + 1));
					odw[j][1][new_state[nr]] = true;
				}
			}
		}
	}
}

int main() {
	vector<int> tab(3);
	for (int i = 0; i < 3; i++) {
		scanf("%d", &space[i]);
	}
	for (int i = 0; i < 3; i++) {
		scanf("%d", &tab[i]);
	}
	queue<pair<vector<int>, int> > order;
	make_move(tab, 1, order);
	while (!order.empty()) {
		vector<int> state = order.front().first;
		int gleb = order.front().second;
		order.pop();
		make_move(state, gleb, order);
	}	
	for (int i = 0; i <= space[2]; i++) {
		printf("%d ", dis[i] - 1);
	}
	printf("\n");
}