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
#include <bits/stdc++.h>
using namespace std;
constexpr int maxN = 1e5+7, INF = 2e9;

int A,B,C,ans[maxN];

struct butle
{
    int a,b,c;
    bool operator<(butle B) const{
        if(a != B.a)
            return a < B.a;
        if(b != B.b)
            return b < B.b;
        return c < B.c;
    }
}pomoc;
map<butle,int>mapka;
queue<pair<butle,int>>q;

void solve(butle butelki, int wyn)
{
    if(mapka[butelki] != 0 && mapka[butelki] < wyn)
        return;

    mapka[butelki] = wyn;
    int a = butelki.a, b = butelki.b, c = butelki.c;
    int pomoc2 = min(a, B - b);
    ans[a] = min(ans[a], wyn), ans[b] = min(ans[b], wyn), ans[c] = min(ans[c], wyn);
    q.push({{a-pomoc2, b+pomoc2, c}, wyn+1});
    pomoc2 = min(a, C - c);
    q.push({{a-pomoc2, b, c+pomoc2}, wyn+1});
    pomoc2 = min(b, A - a);
    q.push({{a+pomoc2, b-pomoc2, c}, wyn+1});
    pomoc2 = min(b, C - c);
    q.push({{a, b-pomoc2, c+pomoc2}, wyn+1});
    pomoc2 = min(c, A - a);
    q.push({{a+pomoc2, b, c-pomoc2}, wyn+1});
    pomoc2 = min(c, B - b);
    q.push({{a, b+pomoc2, c-pomoc2}, wyn+1});
}

int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

int a,b,c;
cin>>A>>B>>C;
cin>>a>>b>>c;

for(int i=0;i<=C;i++)
    ans[i] = INF;
pomoc = {a,b,c};
q.push({pomoc, 0});

while(!q.empty())
{
    solve(q.front().first, q.front().second);
    q.pop();
}
for(int i=0;i<=C;i++)
    cout<<(ans[i] != INF ? ans[i] : -1)<<' ';
}
/*

2 7 9
1 3 6

*/