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
#include <bits/stdc++.h>
#define rep(a, b) for(int i = a; i<=b; ++i)
using namespace std;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int size_a, size_b, size_c;
	cin >> size_a >> size_b >> size_c;

	int a, b, c;
	cin >> a >> b >> c;

	vector <int> ans(max(size_a, max(size_b, size_c))+1, -1);
	map <vector <int>, int> options;
	options[{a, b, c}] = true;

	queue <vector<int>> bfs;
	bfs.push({a, b, c, 0});

	while(!bfs.empty()){
		vector <int> act = bfs.front();
		bfs.pop();

		//cout << act[0] << " " << act[1] << " " << act[2] << ", seria: " << act[3] << "\n";

		rep(0, 2){
			if(ans[act[i]] == -1) ans[act[i]] = act[3];
		}

		//przelewamy z 0
		if(act[1] < size_b){
			if(act[0] < size_b-act[1]){
				if(options[{0, act[1]+act[0], act[2]}] == false){
					bfs.push({0, act[1]+act[0], act[2], act[3]+1});
					options[{0, act[1]+act[0], act[2]}] = true;
				}
			}else if(options[{act[0]-(size_b-act[1]), size_b, act[2]}] == false){
					bfs.push({act[0]-(size_b-act[1]), size_b, act[2], act[3]+1});
					options[{act[0]-(size_b-act[1]), size_b, act[2]}] = true;
				  }
		}

		if(act[2] < size_c){
			if(act[0] < size_c-act[2]){
				if(options[{0, act[1], act[2]+act[0]}] == false){
					bfs.push({0, act[1], act[2]+act[0], act[3]+1});
					options[{0, act[1], act[2]+act[0]}] = true;
				}
			}else if(options[{act[0]-(size_c-act[2]), act[1], size_c}] == false){
					bfs.push({act[0]-(size_c-act[2]), act[1], size_c, act[3]+1});
					options[{act[0]-(size_c-act[2]), act[1], size_c}] = true;
				  }
		}

		//przelewamy z 1
		if(act[0] < size_a){
			if(act[1] < size_a-act[0]){
				if(options[{act[0]+act[1], 0, act[2]}] == false){
					bfs.push({act[0]+act[1], 0, act[2], act[3]+1});
					options[{act[0]+act[1], 0, act[2]}] = true;
				}
			}else if(options[{size_a, act[1]-(size_a-act[0]), act[2]}] == false){
					bfs.push({size_a, act[1]-(size_a-act[0]), act[2], act[3]+1});
					options[{size_a, act[1]-(size_a-act[0]), act[2]}] = true;
				  }
		}

		if(act[2] < size_c){
			if(act[1] < size_c-act[2]){
				if(options[{act[0], 0, act[2]+act[1]}] == false){
					bfs.push({act[0], 0, act[2]+act[1], act[3]+1});
					options[{act[0], 0, act[2]+act[1]}] = true;
				}
			}else if(options[{act[0], act[1]-(size_c-act[2]), size_c}] == false){
					bfs.push({act[0], act[1]-(size_c-act[2]), size_c, act[3]+1});
					options[{act[0], act[1]-(size_c-act[2]), size_c}] = true;
				  }
		}

		//przelewamy z 2
		if(act[0] < size_a){
			if(act[2] < size_a-act[0]){
				if(options[{act[0]+act[2], act[1], 0}] == false){
					bfs.push({act[0]+act[2], act[1], 0, act[3]+1});
					options[{act[0]+act[2], act[1], 0}] = true;
				}
			}else if(options[{size_a, act[1], act[2]-(size_a-act[0])}] == false){
					bfs.push({size_a, act[1], act[2]-(size_a-act[0]), act[3]+1});
					options[{size_a, act[1], act[2]-(size_a-act[0])}] = true;
				  }
		}

		if(act[1] < size_b){
			if(act[2] < size_b-act[1]){
				if(options[{act[0], act[1]+act[2], 0}] == false){
					bfs.push({act[0], act[1]+act[2], 0, act[3]+1});
					options[{act[0], act[1]+act[2], 0}] = true;
				}
			}else if(options[{act[0], size_b, act[2]-(size_b-act[1])}] == false){
					bfs.push({act[0], size_b, act[2]-(size_b-act[1]), act[3]+1});
					options[{act[0], size_b, act[2]-(size_b-act[1])}] = true;
				  }
		}
	}

	rep(0, max(size_a, max(size_b, size_c))) cout << ans[i] << " ";
	cout << "\n";
}