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
#include<bits/stdc++.h>
using namespace std;
namespace std {
    template<>
    struct hash<tuple<int, int, int>> {
        size_t operator()(const tuple<int, int, int> &t) const {
            return (1LL*get<0>(t)*1696969*1696969) ^ (1LL*get<1>(t)*1696969) ^ get<2>(t);
        }
    };
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int aa,bb,cc;
    cin>>aa>>bb>>cc;
    int d,e,f;
    cin>>d>>e>>f;
    vector<int>res(cc+1,INT_MAX);
    //res[a]=0;
    //res[b]=0;
    //res[c]=0;
    unordered_map<tuple<int,int,int>, long long>dist;
    queue<pair<int,tuple<int,int,int>>>q;
    q.push(make_pair(0,make_tuple(d,e,f)));
    dist[{d,e,f}]=1;
    while(!q.empty()){
        auto [a,b,c]=q.front().second;
        //cout<<a<< " "<<b<< " " <<c<<'\n';
        int distsofar=q.front().first;
        q.pop();
        res[a]=min(res[a],distsofar);
        res[b]=min(res[b],distsofar);
        res[c]=min(res[c],distsofar);
        //a-->b
        int transfer=min(a,bb-b);
        tuple<int,int,int>newv={a-transfer,b+transfer,c};
        //cout<<a<< " "<<b<<" "<<c<<" "<<(e-b)<<'\n';
        //cout<<transfer;
        //cout<<(get<1>(newv));
        //cout<<(newv==make_tuple(aa,bb,cc));
        if(dist[newv]==0){
            q.push(make_pair(distsofar+1,newv));
            dist[newv]=1;
        }
        //a-->c
        transfer=min(a,cc-c);
        newv={a-transfer,b,c+transfer};
        if(dist[newv]==0){
            q.push(make_pair(distsofar+1,newv));
            dist[newv]=1;
        }
        //b-->a
        transfer=min(b,aa-a);
        newv={a+transfer,b-transfer,c};
        if(dist[newv]==0){
            q.push(make_pair(distsofar+1,newv));
            dist[newv]=1;
        }
        //b-->c
        transfer=min(b,cc-c);
        newv={a,b-transfer,c+transfer};
        if(dist[newv]==0){
            q.push(make_pair(distsofar+1,newv));
            dist[newv]=1;
        }
        //c-->a
        transfer=min(c,aa-a);
        newv={a+transfer,b,c-transfer};
        if(dist[newv]==0){
            q.push(make_pair(distsofar+1,newv));
            dist[newv]=1;
        }
        //c-->b
        transfer=min(c,bb-b);
        newv={a,b+transfer,c-transfer};
        if(dist[newv]==0){
            q.push(make_pair(distsofar+1,newv));
            dist[newv]=1;
        }
    }
    for(auto const &w : res){
        if(w==INT_MAX){
            cout<<-1<<" ";
        }
        else{
            cout<<w<<" ";
        }
    }
}