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

long long MOD = 1e5+1;

struct trie {

    long long a[3];
    int len = 0;
};
trie maxv;
long long count_hash(trie a) {

    return a.a[0]*MOD*MOD + a.a[1]*MOD + a.a[2];
}

trie ruch(trie a,int from,int to) {

   // cout << "PRZELEWAM z " << from << " do " << to <<endl;
    //long long temp = a.a[from];
    trie res = a;
    res.len = a.len +1;
    res.a[from] = max((long long)0,a.a[from] - (maxv.a[to]-a.a[to]));
    res.a[to] = min(maxv.a[to],a.a[to]+a.a[from]);
    //cout << "GENERATED " << res.a[0] << " " << res.a[1] << " " << res.a[2] <<endl;
    return res;
}


int main() {

    ios_base::sync_with_stdio(0);
    cin >> maxv.a[0] >> maxv.a[1] >> maxv.a[2];
    trie start;
    vector<int> able(maxv.a[2]+1,-1);
    queue<trie> kolej;
    cin >> start.a[0] >> start.a[1] >> start.a[2];
    map<long long,bool> mapa;
    mapa[count_hash(start)] = true;
    kolej.push(start);
    long long ile = 0;
    while(!kolej.empty() && ile != maxv.a[2] + 1) {
       // cout << "MIELE" <<endl;
        trie curr = kolej.front();
       // cout << "MIELE " << curr.a[0] << " " << curr.a[1] << " " << curr.a[2] <<endl;
        kolej.pop();
        for(int k=0;k<3;k++) {
            if(able[curr.a[k]] == -1) {
                able[curr.a[k]] = curr.len;
                ile++;
            }
        }
        for(int k=0;k<3;k++) {
            for(int j=0;j<3;j++) {
                if(j!=k) {
                    trie next = ruch(curr,k,j);
                    if(!mapa[count_hash(next)]) {
                        mapa[count_hash(next)] = true;
                        kolej.push(next);
                    }
                }
            }
        }
    }
    for(auto t:able) {
        cout << t<< " ";
    }

}