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
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <tuple>
#include <deque>
using namespace std;

#define LL long long

LL b1,b2,b3,o1,o2,o3;

set<tuple<LL,LL,LL>> odw;
deque<pair<tuple<LL,LL,LL>,LL>> q;

LL odl=0;

map<LL,LL> s;

LL zostalo(LL o1, LL o2, LL b)
{
	if(o1+o2>b) return o1+o2-b;
	return 0;
}

LL przelane(LL o1, LL o2, LL b)
{
	if(o1+o2>b) return b;
	return o1+o2;
}

void policz(tuple<LL,LL,LL> t, LL odl)
{
	//printf("policz %lld %lld %lld odl %lld\n",get<0>(t),get<1>(t),get<2>(t),odl);
	if(odw.find(t) != odw.end()) return;
	odw.insert(t);
	auto [o1,o2,o3] = t;
	if(s.find(o1) == s.end()) s[o1]=odl;
	if(s.find(o2) == s.end()) s[o2]=odl;
	if(s.find(o3) == s.end()) s[o3]=odl;
	q.push_back(make_pair(make_tuple(zostalo(o1,o2,b2),przelane(o1,o2,b2),o3),odl+1));
	q.push_back(make_pair(make_tuple(zostalo(o1,o3,b3),o2,przelane(o1,o3,b3)),odl+1));
	q.push_back(make_pair(make_tuple(o1,zostalo(o2,o3,b3),przelane(o2,o3,b3)),odl+1));
	q.push_back(make_pair(make_tuple(przelane(o2,o1,b1),zostalo(o2,o1,b1),o3),odl+1));
	q.push_back(make_pair(make_tuple(o1,przelane(o3,o2,b2),zostalo(o3,o2,b2)),odl+1));
	q.push_back(make_pair(make_tuple(przelane(o3,o1,b1),o2,zostalo(o3,o1,b1)),odl+1));
}



int main() {
	scanf("%lld%lld%lld%lld%lld%lld",&b1,&b2,&b3,&o1,&o2,&o3);
	
	q.push_back(make_pair(make_tuple(o1,o2,o3),0));

	while(s.size() < b3+1 && !q.empty())
	{
		auto [t,od] = *(q.begin());
		q.pop_front();
		policz(t,od);
	}
	
	for(int i=0;i<=b3;i++)
	{
		auto it = s.find(i);
		if(it!=s.end()) printf("%lld ",it->second);
		else printf("-1 ");
	}
	
	return 0;
}