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
#include <iostream>
#include <bitset>
#include <map>
#include <algorithm>
#include <utility>
#include <queue>
using namespace std;
struct st{
        int a, b, c, time;
};
int A, B, C, x, y, z, tabwyn[100001];
bitset<100001> bs;
map<unsigned long long, bool> mp;
queue<st> q;
void recc(int a, int b, int c, int time){

        q.push({a, b, c, 0});
        while(!q.empty()){
                a = q.front().a;
                b = q.front().b;
                c = q.front().c;
                time = q.front().time;

                q.pop();

                //printf("\n%d %d %d", a, b, c);

                if(!bs[a]) tabwyn[a] = time;
                else tabwyn[a] = min(tabwyn[a], time);

                if(!bs[b]) tabwyn[b] = time;
                else tabwyn[b] = min(tabwyn[b], time);

                if(!bs[c]) tabwyn[c] = time;
                else tabwyn[c] = min(tabwyn[c], time);

                bs[a] = 1;
                bs[b] = 1;
                bs[c] = 1;


                //add2a
                if(b){
                        if(a + b > A){
                                if(!mp[A*1e13+(b - (A-a))*1e07+c]){
                                        mp[A*1e13+(b - (A-a))*1e07+c] = 1;
                                        //recc(A, b - (A-a), c, time+1);
                                        q.push({A, b - (A-a), c, time+1});
                                }
                        }
                        else if(!mp[(a+b)*1e13+0*1e07+c]){
                                mp[(a+b)*1e13+0*1e07+c] = 1;
                                //recc(a + b, 0, c, time+1);
                                q.push({a + b, 0, c, time+1});

                        }
                }
                if(c){
                        if(a + c > A){
                                if(!mp[A*1e13+b*1e07+(c - (A-a))]){
                                        mp[A*1e13+b*1e07+(c - (A-a))] = 1;
                                        //recc(A, b, c - (A-a), time+1);
                                        q.push({A, b, c - (A-a), time+1});
                                }
                        }
                        else if(!mp[(a+c)*1e13+b*1e07+0]){
                                mp[(a+c)*1e13+b*1e07+0] = 1;
                                //recc(a + c, b, 0, time+1);
                                q.push({a + c, b, 0, time+1});
                        }
                }
                //add2b
                if(a){
                        if(b + a > B){
                                if(!mp[(a - (B-b))*1e13+B*1e07+c]){
                                        mp[(a - (B-b))*1e13+B*1e07+c] = 1;
                                        //recc(a - (B-b), B, c, time+1);
                                        q.push({a - (B-b), B, c, time+1});
                                }
                        }
                        else if(!mp[0*1e13+(b + a)*1e07+c]){
                                mp[0*1e13+(b + a)*1e07+c] = 1;
                                //recc(0, b + a, c, time+1);
                                q.push({0, b + a, c, time+1});
                        }
                }
                if(c){
                        if(b + c > B){
                                if(!mp[a*1e13+B*1e07+c-(B-b)]){
                                        mp[a*1e13+B*1e07+c-(B-b)] = 1;
                                        //recc(a, B, c - (B-b), time+1);
                                        q.push({a, B, c - (B-b), time+1});
                                }
                        }
                        else if(!mp[a*1e13+(b + c)*1e07+0]){
                                mp[a*1e13+(b + c)*1e07+0] = 1;
                                //recc(a, b + c, 0, time+1);
                                q.push({a, b + c, 0, time+1});
                        }
                }
                //add2c
                if(a){
                        if(c + a > C){
                                if(!mp[(a - (C-c))*1e13+b*1e07+C]){
                                        mp[(a - (C-c))*1e13+b*1e07+C] = 1;
                                        //recc(a - (C-c), b, C, time+1);
                                        q.push({a - (C-c), b, C, time+1});
                                }
                        }
                        else if(!mp[0*1e13+b*1e07+(c+a)]){
                                mp[0*1e13+b*1e07+(c+a)] = 1;
                                //recc(0, b, c + a, time+1);
                                q.push({0, b, c + a, time+1});
                        }
                }
                if(b){
                        if(c + b > C){
                                if(!mp[a*1e13+(b - (C-c))*1e07+C]){
                                        mp[a*1e13+(b - (C-c))*1e07+C] = 1;
                                        //recc(a, b - (C-c), C, time+1);
                                        q.push({a, b - (C-c), C, time+1});
                                }
                        }
                        else if(!mp[a*1e13+0*1e07+(c+b)]){
                                mp[a*1e13+0*1e07+(c+b)] = 1;
                                //recc(a, 0, c + b, time+1);
                                q.push({a, 0, c + b, time+1});
                        }
                }
        }
}
int main()
{
    scanf("%d%d%d%d%d%d", &A, &B, &C, &x, &y, &z);

    recc(x, y, z, 0);

    for(int i = 0; i <= C; i++){
            if(bs[i]) printf("%d ", tabwyn[i]);
            else printf("-1 ");
    }
    return 0;
}