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

#define int long long

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);
        }
    };
}

struct kub{
	int a;
	int b;
	int c;
};


main()
{
        int A, B, C, a, b, c;
        cin>>A>>B>>C>>a>>b>>c;
        unordered_map<tuple<int, int, int>, long long> dist;
        dist[{a,b,c}] = 0;
        queue<kub> q;
        q.push({a,b,c});
        vector<int> res(C+1, LLONG_MAX);
        res[c]=0;
        res[b]=0;
        res[a]=0;
        
        while(!q.empty())
        {
        	kub k=q.front();
        	
        	res[k.a]=min(res[k.a], dist[{k.a, k.b, k.c}]);
        	res[k.b]=min(res[k.b], dist[{k.a, k.b, k.c}]);
        	res[k.c]=min(res[k.c], dist[{k.a, k.b, k.c}]);
        	q.pop();
        	
            if(k.a<A && k.b>0)
            {
                if(dist[make_tuple(k.a+min(A-k.a,k.b), k.b-min(A-k.a,k.b), k.c)]>dist[{k.a, k.b, k.c}]+1 || dist[make_tuple(k.a+min(A-k.a,k.b), k.b-min(A-k.a,k.b), k.c)]==0){
                q.push({k.a+min(A-k.a,k.b), k.b-min(A-k.a,k.b), k.c});
                dist[make_tuple(k.a+min(A-k.a,k.b), k.b-min(A-k.a,k.b), k.c)]=dist[{k.a, k.b, k.c}]+1;
                }

            }
            if(k.b<B && k.a>0)
            {
                if(dist[make_tuple(k.a-min(B-k.b,k.a),k.b+min(B-k.b,k.a),  k.c)]>dist[{k.a, k.b, k.c}]+1 || dist[make_tuple(k.a-min(B-k.b,k.a),k.b+min(B-k.b,k.a),  k.c)]==0){
                q.push({k.a-min(B-k.b,k.a),k.b+min(B-k.b,k.a),  k.c});
                dist[make_tuple(k.a-min(B-k.b,k.a),k.b+min(B-k.b,k.a),  k.c)]=dist[{k.a, k.b, k.c}]+1;
                }

            }


            if(k.a<A && k.c>0)
            {
                if(dist[make_tuple(k.a+min(A-k.a,k.c), k.b, k.c-min(A-k.a,k.c))]>dist[{k.a, k.b, k.c}]+1 || dist[make_tuple(k.a+min(A-k.a,k.c), k.b, k.c-min(A-k.a,k.c))]==0){
                q.push({k.a+min(A-k.a,k.c), k.b, k.c-min(A-k.a,k.c)});
                dist[make_tuple(k.a+min(A-k.a,k.c), k.b, k.c-min(A-k.a,k.c))]=dist[{k.a, k.b, k.c}]+1;
                }

            }
            if(k.c<C && k.a>0)
            {
                if(dist[make_tuple(k.a-min(C-k.c,k.a), k.b, k.c+min(C-k.c,k.a))]>dist[{k.a, k.b, k.c}]+1 || dist[make_tuple(k.a-min(C-k.c,k.a), k.b, k.c+min(C-k.c,k.a))]==0){
                q.push({k.a-min(C-k.c,k.a), k.b, k.c+min(C-k.c,k.a)});
                dist[make_tuple(k.a-min(C-k.c,k.a), k.b, k.c+min(C-k.c,k.a))]=dist[{k.a, k.b, k.c}]+1;
                }

            }

            if(k.b<B && k.c>0)
            {
                if(dist[make_tuple(k.a, k.b+min(B-k.b,k.c), k.c-min(B-k.b,k.c))]>dist[{k.a, k.b, k.c}]+1 || dist[make_tuple(k.a, k.b+min(B-k.b,k.c), k.c-min(B-k.b,k.c))]==0){
                q.push({k.a, k.b+min(B-k.b,k.c), k.c-min(B-k.b,k.c)});
                dist[make_tuple(k.a, k.b+min(B-k.b,k.c), k.c-min(B-k.b,k.c))]=dist[{k.a, k.b, k.c}]+1;
                }

            }
            if(k.c<C && k.b>0)
            {
                if(dist[make_tuple(k.a, k.b-min(C-k.c,k.b), k.c+min(C-k.c,k.b))]>dist[{k.a, k.b, k.c}]+1 || dist[make_tuple(k.a, k.b-min(C-k.c,k.b), k.c+min(C-k.c,k.b))]==0){
                q.push({k.a, k.b-min(C-k.c,k.b), k.c+min(C-k.c,k.b)});
                dist[make_tuple(k.a, k.b-min(C-k.c,k.b), k.c+min(C-k.c,k.b))]=dist[{k.a, k.b, k.c}]=dist[{k.a, k.b, k.c}]+1;
                }

            }
        	
        }
        
        for(int i=0; i<=C; i++){
        	if(res[i]==LLONG_MAX)
        		cout<<-1<<" ";
        	else
        	cout<<res[i]<<" ";
    }
}