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

struct but{
        int a;
        int b;
        int c;
        int il;
};


int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int ba,bb,bc;
    int a,b,c,k,przel;

    cin>>ba>>bb>>bc;
    cin>>a>>b>>c;

    vector <int> wyn(bc+1,-1); 
    queue <but> kol;
    but e;

    set<tuple <int,int,int>> zb;

    kol.push({a,b,c,0});

    int j=0;
    for (j=0;j<10000000;j++){
        
        if (kol.empty()) break;
        e=kol.front();
        kol.pop();
        a=e.a;
        b=e.b;
        c=e.c;
        k=e.il;

        if (zb.find({a,b,c}) == zb.end()){
            zb.insert({a,b,c});
        }else{
            continue;
        }

        if (wyn[a]==-1) wyn[a]=k;
        if (wyn[b]==-1) wyn[b]=k;
        if (wyn[c]==-1) wyn[c]=k;

        //A->B
        przel=min(a,bb-b);
        if (przel) kol.push({a-przel,b+przel,c,k+1});

        //A->C
        przel=min(a,bc-c);
        if (przel) kol.push({a-przel,b,c+przel,k+1});
        //B->A
        przel=min(b,ba-a);
        if (przel) kol.push({a+przel,b-przel,c,k+1});
        //B->C
        przel=min(b,bc-c);
        if (przel) kol.push({a,b-przel,c+przel,k+1});
        // C->A
        przel=min(c,ba-a);
        if (przel) kol.push({a+przel,b,c-przel,k+1});
        // C->B
        przel=min(c,bb-b);
        if (przel) kol.push({a,b+przel,c-przel,k+1});
    }
    // cout<<j<<endl;
    for (int i=0;i<=bc;i++){
        cout<<wyn[i]<<" ";
    }
    cout<<"\n";
    return 0;
}