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
#include <iostream>
#include <set>
#include <tuple>
#include <queue>
using namespace std;

const int maxN = 1e5+5;
int A, B, C;
int ans[maxN];
set< tuple<int,int,int> > dane;
queue< pair< pair<int,int>,pair<int,int> > > kolejka;

void DFS(int a, int b, int c, int time)
{
    ans[a] = min(ans[a], time);
    ans[b] = min(ans[b], time);
    ans[c] = min(ans[c], time);

    int rozmiar = dane.size();
    dane.insert(make_tuple(a - (min(a+b, B) - b), min(a+b, B), c));
    if(dane.size() != rozmiar) {
        kolejka.push(make_pair( make_pair(a - (min(a+b, B) - b), min(a+b, B)),make_pair(c, time+1) ));
        rozmiar++;
    }

    dane.insert(make_tuple(min(a+b, A), b - (min(a+b, A) - a), c));
    if(dane.size() != rozmiar) {
        rozmiar++;
        kolejka.push(make_pair( make_pair(min(a+b, A), b - (min(a+b, A) - a)),make_pair(c, time+1) ));
    }

    dane.insert(make_tuple(a - (min(a+c, C) - c), b, min(a+c, C)));
    if(dane.size() != rozmiar) {
        rozmiar++;
        kolejka.push(make_pair( make_pair(a - (min(a+c, C) - c), b),make_pair(min(a+c, C), time+1) ));
    }

    dane.insert(make_tuple(min(a+c, A), b, c - (min(a+c, A) - a)));
    if(dane.size() != rozmiar) {
        rozmiar++;
        kolejka.push(make_pair( make_pair(min(a+c, A), b),make_pair(c - (min(a+c, A) - a), time+1) ));
    }

    dane.insert(make_tuple(a, b - (min(c+b, C) - c), min(b+c, C)));
    if(dane.size() != rozmiar) {
        rozmiar++;
        kolejka.push(make_pair( make_pair(a, b - (min(c+b, C) - c)),make_pair(min(b+c, C), time+1) ));
    }

    dane.insert(make_tuple(a, min(c+b, B), c - (min(b+c, B) - b)));
    if(dane.size() != rozmiar) {
        rozmiar++;
        kolejka.push(make_pair( make_pair(a, min(c+b, B)),make_pair(c - (min(b+c, B) - b), time+1) ));
    }
}

void solve()
{
    int a, b, c;
    cin >> A >> B >> C;
    cin >> a >> b >> c;
    for(int i = 0; i <= C; i++)
        ans[i] = maxN;

    kolejka.push(make_pair( make_pair(a,b),make_pair(c, 0) ));
    while(!kolejka.empty())
    {
        DFS(kolejka.front().first.first,kolejka.front().first.second,kolejka.front().second.first,kolejka.front().second.second);
        kolejka.pop();
    }

    for(int i = 0; i <= C; i++) {
        if(ans[i] == maxN)
            cout << -1 << " ";
        else
            cout << ans[i] << " ";
    }
}

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

    solve();

    return 0;
}