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;


int am;
int bm;
int cm;


int as,bs,cs;


set< vector<int> > mp;


int tab[100001];



int main()
{

    for (int i=0;i<100001;++i)
    {
        tab[i] = INT32_MAX;
    }
    cin >> am >> bm >> cm;
    cin >> as >> bs >> cs;

    queue<pair<vector<int> , int >> q;
    q.push( {vector<int>{as,bs,cs},0  });
    while (!q.empty())
    {
        auto top = q.front();
        q.pop();
        if (mp.find(top.first) != mp.end())
        continue;
        mp.insert(top.first);

        int a = top.first[0];
        int b = top.first[1];
        int c = top.first[2];

        tab[a] = min (tab[a] , top.second);
        tab[b] = min (tab[b] , top.second);
        tab[c] = min (tab[c] , top.second);


        int nxt = top.second+1;

        int tmp = min(bm -b,a);
        q.push({ vector<int>{a-tmp,b+tmp,c}, nxt} );

        tmp = min(cm -c,a);
        q.push({ vector<int>{a-tmp,b,c+tmp}, nxt} );

        tmp = min(cm-c,b);
        q.push({ vector<int>{a,b-tmp,c+tmp}, nxt} );


        tmp = min(b,am-a);
        q.push({ vector<int>{a+tmp,b-tmp,c}, nxt} );

        tmp = min(c,am-a);
        q.push({ vector<int>{a+tmp,b,c-tmp}, nxt} );

        tmp = min(c,bm-b);
        q.push({ vector<int>{a,b+tmp,c-tmp}, nxt} );
    }

    for (int i=0;i<=cm ;++i)
    {
        cout << (tab[i] == INT32_MAX ? -1 : tab[i]) <<" ";
    }
    cout << endl;
    


}

/*

2 7 9
1 3 6

100000 1 100000
2137 1 100000

*/