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

#define pb push_back
#define f first
#define s second
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()

#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define vvi vector<vi>

#define ll long long

template<class T> istream & operator >> (istream&is, vector<T> & vec){ for(T & el : vec) is >> el; return is; }

const int N = 1e6 + 7;
int n;

int DP[N];

void solve(){
    for(int i = 0; i < N; i++)
        DP[i] = -1;

    vi start(3), stan(3);
    cin >> start >> stan;

    map<vi, int> dist;
    dist[start] = 0;

    queue<vi> kol;
    kol.push(stan);

    while(sz(kol)){
        vi stan = kol.front();
        kol.pop();

        for(int i = 0; i < 3; i++)
            if(DP[stan[i]] == -1)
                DP[stan[i]] = dist[stan];
        
        for(int i = 0; i < 3; i++){
            for(int j = 0; j < 3; j++){
                if(i == j)
                    continue;

                int przel = min(stan[i], start[j] - stan[j]);
                vi nowy_stan = stan;
                nowy_stan[i] -= przel;
                nowy_stan[j] += przel;

                if(not dist.count(nowy_stan)){
                    dist[nowy_stan] = dist[stan] + 1;
                    kol.push(nowy_stan);
                }
            }
        }
    }

    for(int i = 0; i <= start[2]; i++)
        cout << DP[i] << ' ';
    cout << '\n';
}

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

    int testy = 1;
    // cin >> testy;

    while(testy--)
        solve();

    return 0;
}