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

int A, B, C;
long long C2, X;
const long long MAX_C=100001;
const int INF = 1000000;
int T[MAX_C];




void rek(int a, int b, int c, int iter) {
    if(iter>8)return;
    T[a]=min(T[a],iter);
    T[b]=min(T[b],iter);
    T[c]=min(T[c],iter);

    int a1,b1,c1;
    // a -> b
    b1 = min(a+b,B);
    a1 = a - (b1-b);
    rek(a1,b1,c,iter+1);

    // a -> c
    c1 = min(a+c,C);
    a1 = a - (c1-c);
    rek(a1,b,c1,iter+1);

    // b -> a
    a1 = min(a+b,A);
    b1 = b - (a1-a);
    rek(a1,b1,c,iter+1);

    // b -> c
    c1 = min(b+c,C);
    b1 = b - (c1-c);
    rek(a,b1,c1,iter+1);

    // c -> a
    a1 = min(a+c,A);
    c1 = c - (a1-a);
    rek(a1,b,c1,iter+1);

    // c -> b
    b1 = min(b+c,B);
    c1 = c - (b1-b);
    rek(a,b1,c1,iter+1);


}

struct Q{
    int a,b,c,w;
    Q(){}
    Q(int _a, int _b, int _c, int _w) {
        a = _a;
        b = _b;
        c = _c;
        w = _w;
    }
};
deque<Q> kolejka;
set<long long>S;

void bfs(int _a, int _b, int _c) {
    kolejka.push_back(Q(_a,_b,_c,0));
    S.insert((long long)_a*C2+(long long)_b *(long long) C +(long long) _c);
    while(!kolejka.empty()) {
        Q k = kolejka.front();
        int a = k.a;
        int b = k.b;
        int c = k.c;
        int w = k.w;

        T[a]=min(T[a],w);
        T[b]=min(T[b],w);
        T[c]=min(T[c],w);
        
        kolejka.pop_front();
        // 
         int a1,b1,c1;
        // a -> b
        b1 = min(a+b,B);
        a1 = a - (b1-b);
        X = (long long)a1*C2+(long long)b1 *(long long) C +(long long) c;
        if(S.count(X)==0) {
            S.insert(X);
            kolejka.push_back(Q(a1,b1,c,w+1));
        }


        // a -> c
        c1 = min(a+c,C);
        a1 = a - (c1-c);
        X = (long long)a1*C2+(long long)b *(long long) C +(long long) c1;
        if(S.count(X)==0) {
            S.insert(X);
            kolejka.push_back(Q(a1,b,c1,w+1));
        }

        // b -> a
        a1 = min(a+b,A);
        b1 = b - (a1-a);
        X = (long long)a1*C2+(long long)b1 *(long long) C +(long long) c;
        if(S.count(X)==0) {
            S.insert(X);
            kolejka.push_back(Q(a1,b1,c,w+1));
        }

        // b -> c
        c1 = min(b+c,C);
        b1 = b - (c1-c);
        X = (long long)a*C2+(long long)b1 *(long long) C +(long long) c1;
        if(S.count(X)==0) {
            S.insert(X);
            kolejka.push_back(Q(a,b1,c1,w+1));
        }

        // c -> a
        a1 = min(a+c,A);
        c1 = c - (a1-a);
        X = (long long)a1*C2+(long long)b *(long long) C +(long long) c1;
        if(S.count(X)==0) {
            S.insert(X);
            kolejka.push_back(Q(a1,b,c1,w+1));
        }

        // c -> b
        b1 = min(b+c,B);
        c1 = c - (b1-b);
        X = (long long)a*C2+(long long)b1 *(long long) C +(long long) c1;
        if(S.count(X)==0) {
            S.insert(X);
            kolejka.push_back(Q(a,b1,c1,w+1));
        }
    }
}
void solve() {
    int a,b,c;
    cin>>A>>B>>C;
    cin>>a>>b>>c;
    C2 = (long long) C * (long long) C;
    for(int i =0;i<=C;i++)
        T[i]=INF;
    //rek(a,b,c,0);
    bfs(a,b,c);
    for(int i =0;i<=C;i++)
        if(T[i]==INF)cout<<-1<<" ";
        else cout<<T[i]<<" ";
}

int main() {
    ios_base::sync_with_stdio(false);
    solve();
    return 0;
}