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
97
98
#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

template<typename _T> inline void _DBG(const char *s, _T x) { cerr << s << " = " << x << "\n"; }
template<typename _T, typename... args> void _DBG(const char *s, _T x, args... a) { while(*s != ',') cerr << *s++; cerr << " = " << x << ','; _DBG(s + 1, a...); }

#ifdef LOCAL
#define _upgrade ios_base::sync_with_stdio(0);
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)
#else
#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define DBG(...) (__VA_ARGS__)
#define cerr if(0) cout
#endif

// ********************** CODE ********************** //

const int N = 1e5 + 7;
const int INF = 1e9 + 7;

int A, B, C, dist[N];
queue<pair<pair<int, int>, int>> Q;
unordered_set<LL> vis;

inline LL compress(int a, int b)
{
    return b | ((LL)a << 32);
}

void check(int a, int b, int c, int d)
{
    if (vis.find(compress(a, b)) == vis.end())
    {
        dist[a] = min(dist[a], d + 1);
        dist[b] = min(dist[b], d + 1);
        dist[c] = min(dist[c], d + 1);
        Q.push({{a, b}, d + 1});
        vis.insert(compress(a, b));
    }
}

int main()
{
    _upgrade
    
    cin >> A >> B >> C;

    int sa, sb, sc;
    cin >> sa >> sb >> sc;

    for (int i = 0; i <= C; i++)
        dist[i] = INF;
 
    dist[sa] = dist[sb] = dist[sc] = 0;

    Q.push({{sa, sb}, 0});
    while(!Q.empty())
    {
        auto [p, d] = Q.front();
        auto [a, b] = p;
        int c = sa + sb + sc - a - b;
        Q.pop();
        
        int x;
        
        x = min(a, B - b);
        check(a - x, b + x, c, d);

        x = min(a, C - c);
        check(a - x, b, c + x, d);

        x = min(b, A - a);
        check(a + x, b - x, c, d);

        x = min(b, C - c);
        check(a, b - x, c + x, d);
    
        x = min(c, A - a);
        check(a + x, b, c - x, d);

        x = min(c, B - b);
        check(a, b + x, c - x, d);
    }

    for (int i = 0; i <= C; i++)
        cout << (dist[i] == INF ? -1 : dist[i]) << " ";
    cout << "\n";

    return 0;
}