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
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include <iostream>
#include <vector>
#include <queue>
#include <set>
using namespace std;

const int MAXC=100001;

int ABC[3];

class Pojemnosci {
public:
	int a, b, c;
	Pojemnosci(int a=0, int b=0, int c=0) : a(a), b(b), c(c) {}
	
	bool operator<(const Pojemnosci &other) const {
	    if(a < other.a)
	        return true;
	    if(a > other.a)
	        return false;
	    if(b < other.b)
	        return true;
	    if(b > other.b)
	        return false;
	    if(c < other.c)
	        return true;
	    else
	        return false;
	}
	
	bool operator==(const Pojemnosci &other) const {
	    return a==other.a && b==other.b && c==other.c;
	}
	
	bool operator!=(const Pojemnosci &other) const {
	    return !(*this == other);
	}
	
	int &poj(int i) {
		if(i == 0)
			return a;
		else if(i==1)
			return b;
		else
			return c;
	}
	
	int poj(int i) const {
		if(i == 0)
			return a;
		else if(i==1)
			return b;
		else
			return c;
	}
	
};

Pojemnosci przelej(const Pojemnosci &p, int from, int to) {
	Pojemnosci p2(p);
	if(ABC[to]>=p2.poj(from)+p2.poj(to)) {
		p2.poj(from) = 0;
		p2.poj(to) = p.poj(from)+p.poj(to);
	} else {
		p2.poj(to) = ABC[to];
		p2.poj(from) = p.poj(from)+p.poj(to) - ABC[to];
	}
	return p2;
}

int main() {
	
	int a, b, c;
	cin >> ABC[0] >> ABC[1] >> ABC[2];
	cin >> a >> b >> c;
	
	set<Pojemnosci> byly;
	int res[MAXC];
	for(int i = 0; i < MAXC; i++)
		res[i] = -1;
	
	std::priority_queue< pair<int, Pojemnosci>, vector<pair<int, Pojemnosci> >, greater<pair<int, Pojemnosci> > > q;
    q.push( pair<int,Pojemnosci>(0,Pojemnosci(a,b,c)) );
 

 
    while(q.size() > 0) {
		auto x = q.top();
		q.pop();
		int &n = x.first;
		auto &p = x.second;
		if(byly.find(p) == byly.end()) {
			if(res[p.a] == -1)
				res[p.a] = n;
			if(res[p.b] == -1)
				res[p.b] = n;
			if(res[p.c] == -1)
				res[p.c] = n;
			byly.insert(p);
			
			q.push( pair<int,Pojemnosci>(n+1, przelej(p,0,1) ) );
			q.push( pair<int,Pojemnosci>(n+1, przelej(p,1,0) ) );
			q.push( pair<int,Pojemnosci>(n+1, przelej(p,0,2) ) );
			q.push( pair<int,Pojemnosci>(n+1, przelej(p,2,0) ) );
			q.push( pair<int,Pojemnosci>(n+1, przelej(p,2,1) ) );
			q.push( pair<int,Pojemnosci>(n+1, przelej(p,1,2) ) );
			
		}
	}
 
	for(int i = 0; i<ABC[2]+1; i++)
		cout << res[i] << " ";
	cout << endl;
	
	
	
	return 0;
}