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
91
92
93
94
95
96
//Author: Piotr Zielinski
#include<bits/stdc++.h>
using namespace std;

template<class C> C reversed(C c) {reverse(c.begin(),c.end()); return c;}
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(X) (X).begin(), (X).end()
#define mp make_pair
#define st first
#define nd second
typedef long long ll;
typedef pair<int,int> pii;

struct State {
    int a, b, c;
    State(int _a, int _b, int _c) : a(_a), b(_b), c(_c) {}

    bool operator<(const State& other) const {
        if(a == other.a && b == other.b)
            return c < other.c;
        else if(a == other.a)
            return b < other.b;
        return a < other.a;
    }
};

ostream& operator<<(ostream& out, const State& state) {
    out << "{" << state.a << " " << state.b << " " << state.c << "}";
    return out;
}

int d = 0, siz;

void update(int newA, int newB, int newC, vector<int>& dist, map<State, bool>& visited, queue<State>& q) {
    if(dist[newA] == -1) {
        dist[newA] = d;
        --siz;
    }
    if(dist[newB] == -1) {
        dist[newB] = d;
        --siz;
    }
    if(dist[newC] == -1) {
        dist[newC] = d;
        --siz;
    }

    if(visited.count({newA, newB, newC}) == 0) {
        q.push({newA, newB, newC});
        visited[{newA, newB, newC}] = true;
    }
}

int32_t main(){
    ios::sync_with_stdio(false);
    int maxA, maxB, maxC, a, b, c;
    cin >> maxA >> maxB >> maxC >> a >> b >> c;

    vector<int> dist(maxC + 1, -1);
    siz = maxC - 2;
    vector<State> layer;
    map<State, bool> visited;
    dist[a] = dist[b] = dist[c] = 0;

    queue<State> q;
    q.push({a, b, c});

    while(!q.empty()) {
        d++;
        // debug(d, visited);

        while(!q.empty()) {
            layer.push_back(q.front());
            q.pop();
        }

        for(State cur : layer) {
            update(min(maxA, cur.a + cur.b), cur.b - (min(maxA, cur.a + cur.b) - cur.a), cur.c, dist, visited, q);
            update(min(maxA, cur.a + cur.c), cur.b, cur.c - (min(maxA, cur.a + cur.c) - cur.a), dist, visited, q);
            update(cur.a - (min(maxB, cur.b + cur.a) - cur.b), min(maxB, cur.b + cur.a), cur.c, dist, visited, q);
            update(cur.a, min(maxB, cur.b + cur.c), cur.c - (min(maxB, cur.b + cur.c) - cur.b), dist, visited, q);
            update(cur.a - (min(maxC, cur.c + cur.a) - cur.c), cur.b, min(maxC, cur.c + cur.a), dist, visited, q);
            update(cur.a, cur.b - (min(maxC, cur.c + cur.b) - cur.c), min(maxC, cur.c + cur.b), dist, visited, q);
        }

        layer.clear();
    }

    for(int di : dist) {
        cout << di << " ";
    }

    cout << "\n";

    return 0;
}