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
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#define st first
#define nd second
using namespace std;

vector<int> ans;
set<pair<int, int>> vis;
int A, B, C;

void bfs(int a, int b, int c)
{
    queue<pair<pair<int, int>, pair<int, int>>> q;
    q.push({{a, b}, {c, 0}});
    while (!q.empty())
    {
        auto p = q.front();
        q.pop();
        int a = p.st.st, b = p.st.nd, c = p.nd.st, t = p.nd.nd;
        auto it = vis.lower_bound({a, b});
        pair<int, int> k = {-1, -1};
        if (it != vis.end()) k = *it;
        if ((k.st == a) && (k.nd == b)) continue;
        vis.insert({a, b});
        if (ans[a] == -1) ans[a] = t;
        if (ans[b] == -1) ans[b] = t;
        if (ans[c] == -1) ans[c] = t;
        q.push({{max(a+b-B, 0), min(a+b, B)}, {c, t+1}});
        q.push({{max(a+c-C, 0), b}, {min(a+c, C), t+1}});
        q.push({{min(a+b, A), max(a+b-A, 0)}, {c, t+1}});
        q.push({{a, max(b+c-C, 0)}, {min(b+c, C), t+1}});
        q.push({{min(a+c, A), b}, {max(a+c-A, 0), t+1}});
        q.push({{a, min(b+c, B)}, {max(b+c-B, 0), t+1}});
    }
    
}

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

    int a, b, c; cin >> A >> B >> C >> a >> b >> c;
    ans = vector<int> (C+1, -1);
    bfs(a, b, c);
    for (int i = 0; i <= C; i++) cout << ans[i] << ' ';
}