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

using namespace std;

int out[100001];
int vtd[100001];

set<pair<int, int> > processed;

vector<pair<int, int> > v1, v2;

int sizes[3];

int a,b,c;
int suma;
int cnt_left;

void process_single(int q, int k) {
	if (!vtd[q]) {
		cnt_left--;
		vtd[q] = 1;
		out[q] = k;
	}
}

void add_pair(pair<int, int> p, int k) {
	if (processed.find(p) == processed.end()) {
		process_single(p.first, k);
		process_single(p.second, k);
		process_single(suma - p.first - p.second,k);
		v2.push_back(p);
		processed.insert(p);
	}
}

void process_pair(pair<int, int> p, int k) {
	// 1 -> 2
	add_pair(make_pair(p.first - min(p.first, sizes[1] - p.second), p.second + min(p.first, sizes[1] - p.second)), k + 1);
	// 1 -> 3
	add_pair(make_pair(p.first - min(p.first, sizes[2] - (suma - p.first - p.second)), p.second), k + 1);
	// 2 -> 1
	add_pair(make_pair(p.first + min(p.second, sizes[0] - p.first), p.second - min(p.second, sizes[0] - p.first)), k + 1);
	// 2 -> 3
	add_pair(make_pair(p.first, p.second - min(p.second, sizes[2] - (suma - p.first - p.second))), k + 1);
	// 3 -> 1
	add_pair(make_pair(p.first + min(suma - p.first - p.second, sizes[0] - p.first), p.second), k + 1);
	// 3 -> 2
	add_pair(make_pair(p.first, p.second + min(suma - p.first - p.second, sizes[1] - p.second)), k + 1);
}

int main() {
	ios::sync_with_stdio(false);
    cin.tie(NULL);


    cin >> sizes[0] >> sizes[1] >> sizes[2];
    cin >> a >> b >> c;

    cnt_left=sizes[2]+1;
    suma=a+b+c;
    int iter = 0;
    
    add_pair(make_pair(a, b), iter);
    swap(v1, v2);
    v2.clear();

    while(v1.size() > 0 && cnt_left > 0) {
    	for(int i = 0; i < v1.size(); i++) {
    		process_pair(v1[i], iter);
    	}
    	iter++;
    	swap(v1, v2);
    	v2.clear();
    }

    for(int i = 0; i <= sizes[2]; i++) {
    	if (vtd[i]) {
    		cout << out[i] << " ";
    	} else {
    		cout << "-1 ";
    	}
    }


	return 0;
}