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
#include <iostream>
#include <map>
#include <queue>
using namespace std;
map <pair<pair<int,int>,int>, bool> m;
int a,b,c,x,y,z,res[100010];
queue <pair<pair<int,int>,int> > kol;
queue <int> dist;
pair <pair<int,int>,int> first(int x, int y, int z){
    //x -> y z
    int temp = min(b - y,x);
    x -= temp; y += temp;
    return make_pair(make_pair(x,y),z);
}
pair <pair<int,int>,int> second(int x, int y, int z){
    //x y -> z
    int temp = min(c - z,y);
    y -= temp; z += temp;
    return make_pair(make_pair(x,y),z);
}
pair <pair<int,int>,int> third(int x, int y, int z){
    //x <- y z
    int temp = min(a - x,y);
    x += temp; y -= temp;
    return make_pair(make_pair(x,y),z);
}
pair <pair<int,int>,int> fourth(int x, int y, int z){
    //x y <- z
    int temp = min(b - y,z);
    y += temp; z -= temp;
    return make_pair(make_pair(x,y),z);
}
pair <pair<int,int>,int> fifth(int x, int y, int z){
    //x -> z
    int temp = min(c - z,x);
    x -= temp; z += temp;
    return make_pair(make_pair(x,y),z);
}
pair <pair<int,int>,int> sixt(int x, int y, int z){
    //x <- z
    int temp = min(a - x,z);
    x += temp; z -= temp;
    return make_pair(make_pair(x,y),z);
}
void update(pair<pair<int,int>,int> temp, int d){
    if(!m[temp]){
        m[temp] = true;
        kol.push(temp);
        dist.push(d+1);
    }
}
void BFS(){
    pair<pair<int,int>,int> beg = make_pair(make_pair(x,y),z);
    kol.push(beg);
    dist.push(0);
    while(!kol.empty()){
        pair<pair<int,int>,int> p = kol.front();
        int x=p.first.first,y=p.first.second,z=p.second;
        int d = dist.front();
        res[x] = min(res[x],d);
        res[y] = min(res[y],d);
        res[z] = min(res[z],d);
        pair<pair<int,int>,int> temp = first(x,y,z);
        update(temp,d);
        temp = second(x,y,z);
        update(temp,d);
        temp = third(x,y,z);
        update(temp,d);
        temp = fourth(x,y,z);
        update(temp,d);
        temp = fifth(x,y,z);
        update(temp,d);
        temp = sixt(x,y,z);
        update(temp,d);
        kol.pop(); dist.pop();
    }
}
int main(){
    ios_base :: sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> a >> b >> c >> x >> y >> z;
    fill(res,res + c + 2,1000000000);
    BFS();
    for(int i = 0; i <= c; i++){
        if(res[i] == 1000000000)
            cout << -1 << " ";
        else
            cout << res[i] << " ";
    }cout << "\n";
    
}