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;

unordered_map<int, int> ans;

#define a first.first
#define b first.second
#define c second

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

    int A[3];
    for(int i = 0; i < 3; i++) {
        cin >> A[i];
    }

    vector<pair<pair<int, int>, int>> new_q;
    vector<pair<pair<int, int>, int>> q;
    map<pair<pair<int, int>, int>, bool> checked;
    unordered_map<int, int> ans;

    int buff[3];
    for(int i = 0; i < 3; i++) {
        cin >> buff[i];
    }

    new_q.push_back({{buff[0], buff[1]}, buff[2]});

    int step = 1;
    while(new_q.size()) {
        q = new_q;
        new_q.clear();
        while(q.size()) {
            pair<pair<int, int>, int> curr = q.back();

            if(!checked[curr]) {
                checked[curr] = true;

                if(!ans[curr.a]) {
                    ans[curr.a] = step;
                }
                if(!ans[curr.b]) {
                    ans[curr.b] = step;
                }
                if(!ans[curr.c]) {
                    ans[curr.c] = step;
                }
                

                for(int i = 0; i < 3; i++) {
                    for(int j = 0; j < 3; j++) {
                        if(i == 0 && j == 1) {
                            int diff = min(curr.a, A[j] - curr.b);
                            new_q.push_back({{curr.a - diff, curr.b + diff}, curr.c});
                        } else if(i == 0 && j == 2) {
                            int diff = min(curr.a, A[j] - curr.c);
                            new_q.push_back({{curr.a - diff, curr.b}, curr.c + diff});
                        } else if(i == 1 && j == 0) {
                            int diff = min(curr.b, A[j] - curr.a);
                            new_q.push_back({{curr.a + diff, curr.b - diff}, curr.c});
                        } else if(i == 1 && j == 2) {
                            int diff = min(curr.b, A[j] - curr.c);
                            new_q.push_back({{curr.a, curr.b - diff}, curr.c + diff});
                        } else if(i == 2 && j == 0) {
                            int diff = min(curr.c, A[j] - curr.a);
                            new_q.push_back({{curr.a + diff, curr.b}, curr.c - diff});
                        } else if(i == 2 && j == 1) {
                            int diff = min(curr.c, A[j] - curr.b);
                            new_q.push_back({{curr.a, curr.b + diff}, curr.c - diff});
                        }
                    }
                }
            }

            q.pop_back();
        }
        step++;
    }

    for(int i = 0; i <= A[2]; i++) {
        cout << ans[i] - 1 << " ";
    }
    cout << "\n";

    return 0;
}