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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// Wiktor Cupiał
// V LO Kraków
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define eb emplace_back
#define st first
#define nd second
#define vt vector
#define VAR(__var)  #__var << ": " << __var << " "
#define PAIR(__var) #__var << ": " << __var.first << ", " << __var.second << " "
#define FOR(__var, __start, __end)  for(int __var=__start; __var<__end; ++__var)
#define FORB(__var, __start, __end) for(int __var=__start; __var>__end; --__var)
#define maxi(__x, __y) __x = (__x>__y?__x:__y)
#define mini(__x, __y) __x = (__x<__y?__x:__y)
#define all(__var)     (__var).begin(),(__var).end()
#define rall(__var)    (__var).rbegin(),(__var).rend()
#define sz(__var)      (int)(__var).size()
#define satori         int __test; cin>>__test; while(__test--)
 
#ifndef DEBUG
#define DEBUG 0
#endif
#define debug if(DEBUG)
 
using namespace std;
 
using namespace __gnu_pbds;
template <typename T>
using ord_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
 
// templeos <3
typedef     int16_t i16;
typedef     int32_t i32;
typedef     int64_t i64;
typedef        void  u0;
typedef        bool  u1;
typedef        char  u8;
typedef    uint16_t u16;
typedef    uint32_t u32;
typedef    uint64_t u64;
typedef       float f32;
typedef      double f64;
typedef long double f86;
 
typedef       long long ll;
typedef     long double ld;
typedef   pair<ll, ll> pll;
typedef pair<int, int> pii;
 
const ll INF = 1e18+2137;

namespace std {
    template<>
    struct hash<tuple<int, int, int>> {
        size_t operator()(const tuple<int, int, int> &t) const {
            return (1LL*get<0>(t)*1696969*1696969) ^ (1LL*get<1>(t)*1696969) ^ get<2>(t);
        }
    };
}

void solve()
{
	int a[3];
	int st[3];
	cin >> a[0] >> a[1] >> a[2];
	cin >> st[0] >> st[1] >> st[2];
	
	auto cmp = [](pair<long long, tuple<int, int, int>> l, pair<long long, tuple<int, int, int>> r) {return l.st > r.st;};
	
	unordered_map<tuple<int, int, int>, long long> d;
	unordered_map<tuple<int, int, int>, long long> vis;
	priority_queue<pair<long long, tuple<int, int, int>>, vt<pair<long long, tuple<int, int, int>>>, decltype(cmp)> q(cmp);

	tuple<int, int, int> start_state = {st[0], st[1], st[2]};
	d[start_state] = 0;
	vis[start_state] = 1;
	q.push(mp(0, start_state));

	const int MAXN = max({a[0], a[1], a[2]});
	vt<ll> res(MAXN+2, INF);

	FOR(i, 0, 3)
		res[st[i]] = 0;

	while(!q.empty()) {
		// cout << q.top().st << ' ' << d[q.top().nd] << '\n';
		tuple<int, int, int> state = q.top().nd;
		ll now = q.top().st;
		q.pop();
		
		if(d[state] < now)
			continue;

		auto go = [&](int &nfrom, int &nto, int l, int r, tuple<int, int, int> &nowy) {
			ll from = nfrom;
			ll to = nto;
			if(from == 0 || to == a[r])
				return;
				
			ll jeden = a[r] - to;
			ll ile = 0;
			if(from > jeden) {
				ile = jeden;
				nfrom = from-ile;
				nto = to+ile;	
			}
			else {
				ile = from;
				nfrom = 0;
				nto = to+ile;
			}
		
			ile+=d[state];
			mini(res[get<0>(nowy)], d[state]+1);
			mini(res[get<1>(nowy)], d[state]+1);
			mini(res[get<2>(nowy)], d[state]+1);
				
			if(ile < d[nowy] || !vis[nowy])
				d[nowy] = d[state]+1, q.push(mp(d[nowy], nowy)), vis[nowy] = 1;
		};
			
		tuple<int, int, int> nowy = state;
		go(get<0>(nowy), get<1>(nowy), 0, 1, nowy);
		nowy = state;
		go(get<0>(nowy), get<2>(nowy), 0, 2, nowy);
		nowy = state;
		go(get<1>(nowy), get<0>(nowy), 1, 0, nowy);
		nowy = state;
		go(get<1>(nowy), get<2>(nowy), 1, 2, nowy);
		nowy = state;
		go(get<2>(nowy), get<0>(nowy), 2, 0, nowy);
		nowy = state;
		go(get<2>(nowy), get<1>(nowy), 2, 1, nowy);
	}
	
	FOR(i, 0, MAXN+1) 
		cout << ((res[i]==INF)?(-1):(res[i])) << ' ';
	cout << '\n';
}

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 	
	solve();
	
	return 0;
}