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
157
158
159
160
161
162
163
164
165
#include <iostream> 
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <unordered_set>

using namespace std;
typedef unsigned long long ull;
typedef unsigned int ui;

const int MAXN = 100100;

unordered_set<ull> s;
queue<pair<ui, ull>> q;

ui x, y, z;
int wyn[MAXN] = {};
ull sum;

struct PK {
    ui a, b, c;
    PK(ui a, ui b, ui c): a{a}, b{b}, c{c} {};
};

inline ull pack(ui a, ui b) {
    return ((((ull)a) << 32LL) + (ull) b);
}

void push(ui ln, ui a, ui b) {
    q.push(make_pair(ln, pack(a, b)));
}

pair<ui, PK> get() {
    pair<ui, ull> f = q.front();
    q.pop();
    ui fst = (f.second >> 32LL);
    ui z = sum - fst - f.second;
    return make_pair(f.first, PK(fst, (ui) f.second, z));
}

void add(ui a, ui b) {
    s.insert(pack(a,b));
}

bool find(ui a, ui b) {
    return s.find(pack(a, b)) != s.end();
}

int main() {
    ui a, b, c;
    cin >> x >> y >> z >> a >> b >> c;
    sum = a + b + c;

    for (int i = 0; i <= z; i++) {
        wyn[i] = -1;
    }

    wyn[a] = 0;
    wyn[b] = 0;
    wyn[c] = 0;

    push(0, a, b);
    add(a, b);

    // PK x = get();
    // cout << x.a << ' ' << x.b << ' ' << x.c << endl;
    
    while(!q.empty()) {
        pair<ui, PK> pw = get();
        PK w = pw.second;
        ui ct = pw.first;
        
        // cout << w.a << ' ' << w.b << ' ' << w.c << endl;
        // cout << ct << endl;
        ui pab = min(y-w.b, w.a); 
        // cout << "ponc" << endl;
        if (wyn[w.b+pab] == -1) {
            wyn[w.b+pab] = ct+1;
        }
        if (wyn[w.a-pab] == -1) {
            wyn[w.a-pab] = ct+1;
        }
        if(!find(w.a-pab, w.b+pab)) {
            // cout << "pab: " << w.a-pab << " " << w.b+pab << " " << w.c << endl;
            push(ct+1, w.a-pab, w.b+pab);
            add(w.a-pab, w.b+pab);
        }

        ui pba = min(x-w.a, w.b);
        if (wyn[w.a+pba] == -1) {
            wyn[w.a+pba] = ct+1;
        }
        if (wyn[w.b-pba] == -1) {
            wyn[w.b-pba] = ct+1;
        }
        if(!find(w.a+pba, w.b-pba)) {
            // cout << "pba: " << w.a+pba << " " << w.b+pba << " " << w.c << endl;
            push(ct+1, w.a+pba, w.b-pba);
            add(w.a+pba, w.b-pba);
        }

        ui pac = min(z-w.c, w.a);
        // cout << "pac: " << pac << endl;
        if (wyn[w.c+pac] == -1) {
            wyn[w.c+pac] = ct+1;
        }
        if (wyn[w.a-pac] == -1) {
            wyn[w.a-pac] = ct+1;
        }
        if(!find(w.a-pac, w.b)) {
            // cout << "pac: " << w.a-pac << " " << w.b << " " << w.c+pac << endl;
            push(ct+1, w.a-pac, w.b);
            add(w.a-pac, w.b);
        }

        ui pbc = min(z-w.c, w.b);
        // cout << "pbc: " << pbc << endl;
        if (wyn[w.c+pbc] == -1) {
            wyn[w.c+pbc] = ct+1;
        }
        if (wyn[w.b-pbc] == -1) {
            wyn[w.b-pbc] = ct+1;
        }
        if(!find(w.a, w.b-pbc)) {
            // cout << "pbc: " << w.a << " " << w.b-pbc << " " << w.c+pbc << endl;
            push(ct+1, w.a, w.b-pbc);
            add(w.a, w.b-pbc);
        }

        // cout << "fromc" << endl;
        ui pca = min(x-w.a, w.c);
        if (wyn[w.c-pca] == -1) {
            wyn[w.c-pca] = ct+1;
        }
        if (wyn[w.a+pca] == -1) {
            wyn[w.a+pca] = ct+1;
        }
        if(!find(w.a+pca, w.b)) {
            // cout << "pca: " << w.a+pca << " " << w.b << " " << w.c-pca << endl;
            push(ct+1, w.a+pca, w.b);
            add(w.a+pca, w.b);
        }

        ui pcb = min(y-w.b, w.c);
        if (wyn[w.c-pcb] == -1) {
            wyn[w.c-pcb] = ct+1;
        }
        if (wyn[w.b+pcb] == -1) {
            wyn[w.b+pcb] = ct+1;
        }
        if(!find(w.a, w.b+pcb)) {
            // cout << "pcb: " << w.a << " " << w.b+pcb << " " << w.c-pcb << endl;
            push(ct+1, w.a, w.b+pcb);
            add(w.a, w.b+pcb);
        }
        // cout << "kąc" << endl;
    }
    for(int i = 0; i <= z; i++) {
        cout << wyn[i] << ' ';
    }
    cout << endl;
}