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
// 
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i, p, k) for(int i(p); i < (k); ++i)
typedef long long int ll;
typedef long double ld;
template <typename T = int> inline T in()
{
    T x;
    std::cin >> x;
    return x;
}
std::array <int, 3> p, s;
std::map < std::array <int, 3>, bool > byl;
constexpr int maxc  = 1e5 + 3;
int wyn[maxc];
constexpr std::array <int, 3> abo = {-1, -1, -1};
constexpr int inf = 1e9;
int main()
{
    std::cin.tie(nullptr); std::cout.tie(nullptr); std::ios_base::sync_with_stdio(0);
    rep(i, 0, 3)std::cin >> p[i];
    rep(i, 0, 3)std::cin >> s[i];
    rep(i, 0, p[2]+1)wyn[i] = inf;
    std::queue <std::array <int, 3>> kul;
    kul.push(s);
    kul.push(abo);
    int t(0);
    while(kul.size())
    {
        auto abc(kul.front());
        kul.pop();
        if(abc == abo)
        {
            ++t;
            if(kul.size())kul.push(abo);
            continue;
        }
        if(byl[abc])continue;
        byl[abc] = 1;
        rep(i, 0, 3)if(wyn[abc[i]] > t)wyn[abc[i]] = t;
        rep(i, 0, 3)rep(j, 0, 3)if(i != j)
        {
            auto cp(abc);
            if(cp[i] + cp[j] <= p[j])
            {
                cp[j] += cp[i];
                cp[i] = 0;
            }
            else
            {
                cp[i] -= p[j] - cp[j];
                cp[j] = p[j];
            }
            kul.push(cp);
        }
    }    
    rep(i, 0, p[2]+1)std::cout << (wyn[i] == inf ? -1 : wyn[i])<<' ';
    std::cout << '\n';
    return 0;
}