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
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include <bits/stdtr1c++.h>

#define F first
#define S second
#define ll long long
#define ld long double
#define vi vector < int >
#define pb push_back
#define sz(x) int((x).size())
#define pii pair < int, int >
#define all(x) (x).begin(), (x).end()
#define vpii vector < pii >
#define fenwick(x) ((x) & -(x))
#define debug(x) cout << "[ " << #x << " ]: " << x << "\n";

using namespace std;

//CZY DANE POSORTOWANE, N = 0, N = 1, CZYTANIE TRESCI, < rosnaco, > malejaco

const int MAX = 100000 + 123;

int ans = 1e9, A, B, C, D;

set < pair < pair < int, int >, int > > mapa;

int tab[MAX];

int dfs(pair < pair < int, int >, int > stan)
{
    queue < pair < pair < int, int >, int > > kolejka;

    kolejka.push(stan);
    int ruchy = 1;

    while(!kolejka.empty())
    {
        int rozm = kolejka.size();
        while(rozm--)
        {
            pair < pair < int, int >, int > a1do2 = kolejka.front();
            pair < pair < int, int >, int > a1do3 = kolejka.front();
            pair < pair < int, int >, int > a2do3 = kolejka.front();
            pair < pair < int, int >, int > a3do2 = kolejka.front();
            pair < pair < int, int >, int > a3do1 = kolejka.front();
            pair < pair < int, int >, int > a2do1 = kolejka.front();
            kolejka.pop();
            int zm12 = min(a1do2.F.S + a1do2.F.F, B) - a1do2.F.S;
            a1do2.F.F -= zm12;
            a1do2.F.S += zm12;
            int zm13 = min(a1do3.S + a1do3.F.F, C) - a1do3.S;
            a1do3.F.F -= zm13;
            a1do3.S += zm13;
            int zm23 = min(a2do3.S + a2do3.F.S, C) - a2do3.S;
            a2do3.F.S -= zm23;
            a2do3.S += zm23;
            int zm32 = min(a3do2.F.S + a3do2.S, B) - a3do2.F.S;
            a3do2.S -= zm32;
            a3do2.F.S += zm32;
            int zm31 = min(a3do1.S + a3do1.F.F, A) - a3do1.F.F;
            a3do1.S -= zm31;
            a3do1.F.F += zm31;
            int zm21 = min(a2do1.F.F + a2do1.F.S, A) - a2do1.F.F;
            a2do1.F.S -= zm21;
            a2do1.F.F += zm21;

            tab[a1do2.F.F] = min(tab[a1do2.F.F], ruchy);
            tab[a1do2.F.S] = min(tab[a1do2.F.S], ruchy);
            tab[a1do2.S] = min(tab[a1do2.S], ruchy);

            tab[a1do3.F.F] = min(tab[a1do3.F.F], ruchy);
            tab[a1do3.F.S] = min(tab[a1do3.F.S], ruchy);
            tab[a1do3.S] = min(tab[a1do3.S], ruchy);

            tab[a2do3.F.F] = min(tab[a2do3.F.F], ruchy);
            tab[a2do3.F.S] = min(tab[a2do3.F.S], ruchy);
            tab[a2do3.S] = min(tab[a2do3.S], ruchy);

            tab[a3do2.F.F] = min(tab[a3do2.F.F], ruchy);
            tab[a3do2.F.S] = min(tab[a3do2.F.S], ruchy);
            tab[a3do2.S] = min(tab[a3do2.S], ruchy);

            tab[a3do1.F.F] = min(tab[a3do1.F.F], ruchy);
            tab[a3do1.F.S] = min(tab[a3do1.F.S], ruchy);
            tab[a3do1.S] = min(tab[a3do1.S], ruchy);

            tab[a2do1.F.F] = min(tab[a2do1.F.F], ruchy);
            tab[a2do1.F.S] = min(tab[a2do1.F.S], ruchy);
            tab[a2do1.S] = min(tab[a2do1.S], ruchy);

            if(!mapa.count(a1do2))
            {
                mapa.insert(a1do2);
                kolejka.push(a1do2);
            }
            if(!mapa.count(a1do3))
            {
                mapa.insert(a1do3);
                kolejka.push(a1do3);
            }
            if(!mapa.count(a2do3))
            {
                mapa.insert(a2do3);
                kolejka.push(a2do3);
            }
            if(!mapa.count(a3do2))
            {
                mapa.insert(a3do2);
                kolejka.push(a3do2);
            }
            if(!mapa.count(a3do1))
            {
                mapa.insert(a3do1);
                kolejka.push(a3do1);
            }
            if(!mapa.count(a2do1))
            {
                mapa.insert(a2do1);
                kolejka.push(a2do1);
            }
        }
        ++ruchy;
    }
    return -1;
}



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

    for (int i = 0; i < MAX; ++i)
        tab[i] = 1e9;

    pair < pair < int, int >, int > stan = {{0, 0}, 0};
    cin >> A >> B >> C >> stan.F.F >> stan.F.S >> stan.S;

    tab[stan.F.F] = tab[stan.F.S] = tab[stan.S] = 0;
 

    mapa.insert(stan);

    int ans = dfs(stan);

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

    return 0;
}