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
#include <bits/stdc++.h>
using namespace std;

#define LL long long
#define f first
#define s second

const LL t = 1e5 + 9, inf = 1e9;
const LL mil = 1e6;
LL odp[t];

LL con1(LL a, LL b, LL c) {
    return a + b * mil + c * mil * mil;
}

pair <LL, pair <LL, LL> > con2(LL q) {
    LL a = q % mil;
    q /= mil;
    LL b = q % mil;
    q /= mil;
    LL c = q % mil;
    return {a, {b, c}};
}

map <LL, LL> mapa;

int main() {
    std::ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    LL a0, b0, c0, s[3];
    cin >> s[0] >> s[1] >> s[2] >> a0 >> b0 >> c0;
    priority_queue <pair <LL, LL> > q;
    mapa[con1(a0, b0, c0)] = 0;
    q.push({0, con1(a0, b0, c0)});
    while(q.size() > 0) {
        LL temp1 = q.top().s;
        LL w = -q.top().f;
        q.pop();
        pair <LL, pair <LL, LL> > temp2 = con2(temp1);
        LL v[3];
        v[0] = temp2.f; v[1] = temp2.s.f; v[2] = temp2.s.s;
        for(LL i = 0; i <= 2; i ++) {
            for(LL k = 0; k <= 2; k ++) {
                if(i != k) {
                    LL u[3];
                    for(LL j = 0; j <= 2; j ++) u[j] = v[j];
                    u[i] -= min(v[i], s[k] - v[k]);
                    u[k] += min(v[i], s[k] - v[k]);
                    LL temp3 = con1(u[0], u[1], u[2]);
                    if(mapa.find(temp3) == mapa.end()) {
                        mapa[temp3] = w + 1;
                        q.push({-(w + 1), temp3});
                    }
                    else if(mapa[temp3] > w + 1) {
                        mapa[temp3] = w + 1;
                        q.push({-(w + 1), temp3});
                    }
                }
            }
        }
    }
    for(LL i = 0; i <= s[2]; i ++) odp[i] = inf;
    for(auto i : mapa) {
        pair <LL, pair <LL, LL> > temp = con2(i.f);
        odp[temp.f] = min(odp[temp.f], i.s);
        odp[temp.s.f] = min(odp[temp.s.f], i.s);
        odp[temp.s.s] = min(odp[temp.s.s], i.s);
    }
    for(LL i = 0; i <= s[2]; i ++) {
        if(odp[i] == inf) cout << -1 << ' ';
        else cout << odp[i] << ' ';
    }
    return 0;
}