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
#include <bits/stdc++.h>
#define gc getchar
#define gcu getchar_unlocked
#define fi first
#define se second
#define pb push_back
#define mod ((ll)1e9 + 7)
typedef long long ll;
using namespace std;
//=============================================

int n;
int w[10], ans[1000009];
queue<vector<int>> q;
set<pair<int, pair<int, int>>> s;
void f(vector<int> v, int x, int y)
{
	vector<int> ret = v;
	ret[0]++;
	ret[y] += v[x];
	ret[y] = min(ret[y], w[y]);
	ret[x] -= ret[y] - v[y];
	if (s.count({ret[1], {ret[2], ret[3]}}))
		return;
	s.insert({ret[1], {ret[2], ret[3]}});
	q.push(ret);
}

//=============================================
int main()
{
	for (int i = 1; i <= 3; i++)
		scanf("%d", &w[i]);
	n = w[3] + 1;
	for (int i = 0; i < n; i++)
		ans[i] = -1;
	vector<int> v;
	v.pb(0);
	for (int i = 0, temp; i < 3; i++)
		scanf("%d", &temp), v.pb(temp);
	q.push(v);
	while (!q.empty())
	{
		vector<int> temp = q.front();
		q.pop();
		if (q.size() > 1000000 || temp[0] > 1000000 || s.size() > 1000000)
			break;
		for (int i = 1; i <= 3; i++)
			for (int j = 1; j <= 3; j++)
				if (i != j)
					f(temp, i, j);
		for (int i = 1; i <= 3; i++)
			if (ans[temp[i]] == -1)
				ans[temp[i]] = temp[0];
	}
	for (int i = 0; i < n; i++)
		printf("%d ", ans[i]);
	printf("\n");
}
//=============================================