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
119
120
121
122
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <queue>

using namespace std;

#define N 100005
#define K 100001

typedef tuple<long long, long long, long long> tlll;

long long siz[3];
long long vol[3];

unordered_map<long long, int> dist;

queue<long long> q;

long long ans[N];

long long compress(long long a, long long b, long long c){
	return 1LL * K * K * a + 1LL * K * b + c;
}

tlll decompress(long long v){
	tlll ret;

	get<0>(ret) = v/K/K;
	get<1>(ret) = v/K%K;
	get<2>(ret) = v%K;

	return ret;
}

void bfs(long long s){
	q.push(s);
	dist[s] = 0;

	while(!q.empty()){
		long long v = q.front();
		q.pop();

		long long d = dist[v];
		long long a, b, c;
		tie(a, b, c) = decompress(v);

		if(ans[a] == -1 || d < ans[a]) ans[a] = d;
		if(ans[b] == -1 || d < ans[b]) ans[b] = d;
		if(ans[c] == -1 || d < ans[c]) ans[c] = d;

		long long next = 0;	
		long long diff = 0;

		diff = min(a, siz[1]-b);
		next = compress(a-diff, b+diff, c);
		if(dist.count(next) == 0){
			dist[next] = d+1;
			q.push(next);
		}

		diff = min(b, siz[0]-a);
		next = compress(a+diff, b-diff, c);
		if(dist.count(next) == 0){
			dist[next] = d+1;
			q.push(next);
		}


		diff = min(a, siz[2]-c);
		next = compress(a-diff, b, c+diff);
		if(dist.count(next) == 0){
			dist[next] = d+1;
			q.push(next);
		}

		diff = min(c, siz[0]-a);
		next = compress(a+diff, b, c-diff);
		if(dist.count(next) == 0){
			dist[next] = d+1;
			q.push(next);
		}

		diff = min(b, siz[2]-c);
		next = compress(a, b-diff, c+diff);
		if(dist.count(next) == 0){
			dist[next] = d+1;
			q.push(next);
		}

		diff = min(c, siz[1]-b);
		next = compress(a, b+diff, c-diff);
		if(dist.count(next) == 0){
			dist[next] = d+1;
			q.push(next);
		}
	}
}

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

	for(int i=0;i<N+1;i++) ans[i] = -1;

	for(int i=0;i<3;i++) cin >> siz[i]; 
	for(int i=0;i<3;i++) cin >> vol[i]; 

	//tie(a, b, c) = decompress(compress(a, b, c));

	for(int i=0;i<3;i++){
		ans[vol[i]] = 0;
	}

	bfs(compress(vol[0], vol[1], vol[2]));

	for(int i=0;i<=siz[2];i++){
		cout << ans[i] << " ";
	}

	return 0;
}