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
#include<iostream>
#include<queue>
#include<utility>
#include<map>
using namespace std;
queue<pair<pair<int,int>,pair<int,int> > > kolejka;
int wyniki[1000000];
map<pair<int,pair<int,int> >,int> mapka;
map<pair<int,pair<int,int> >,int>::iterator it;
int main()
{
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int a,b,c,a1,b1,c1;
	cin>>a>>b>>c>>a1>>b1>>c1;
	for(int i=0;i<=c;i++)
        wyniki[i]=-1;
	kolejka.push(make_pair(make_pair(a1,b1),make_pair(c1,0)));
	while(!kolejka.empty())
    {
        pair<pair<int,int>,pair<int,int> > para;
        para=kolejka.front();
        kolejka.pop();
        int x=para.first.first;
        int y=para.first.second;
        int z=para.second.first;
        int koszt=para.second.second;
        it=mapka.find(make_pair(x,make_pair(y,z)));
        if(it!=mapka.end())
            continue;
        //cout<<x<<" "<<y<<" "<<z<<"\n";
        mapka[make_pair(x,make_pair(y,z))]=1;
        if(wyniki[z]==-1)
            wyniki[z]=koszt;
        if(wyniki[x]==-1)
            wyniki[x]=koszt;
        if(wyniki[y]==-1)
            wyniki[y]=koszt;
        it=mapka.find(make_pair(min(a,x+y),make_pair(y-(min(a,x+y)-x),z)));
        if(it==mapka.end())
            kolejka.push(make_pair(make_pair(min(a,x+y),y-(min(a,x+y)-x)),make_pair(z,koszt+1)));
        it=mapka.find(make_pair(x-(min(b,x+y)-y),make_pair(min(b,x+y),z)));
        if(it==mapka.end())
            kolejka.push(make_pair(make_pair(x-(min(b,x+y)-y),min(b,x+y)),make_pair(z,koszt+1)));

        it=mapka.find(make_pair(min(a,x+z),make_pair(y,z-(min(a,x+z)-x))));
        if(it==mapka.end())
            kolejka.push(make_pair(make_pair(min(a,x+z),y),make_pair(z-(min(a,x+z)-x),koszt+1)));
        it=mapka.find(make_pair(x-(min(c,x+z)-z),make_pair(y,min(c,x+z))));
        if(it==mapka.end())
            kolejka.push(make_pair(make_pair(x-(min(c,x+z)-z),y),make_pair(min(c,x+z),koszt+1)));

        it=mapka.find(make_pair(x,make_pair(min(b,y+z),z-(min(b,y+z)-y))));
        if(it==mapka.end())
            kolejka.push(make_pair(make_pair(x,min(b,y+z)),make_pair(z-(min(b,y+z)-y),koszt+1)));
        it=mapka.find(make_pair(x,make_pair(y-(min(c,y+z)-z),min(c,y+z))));
        if(it==mapka.end())
            kolejka.push(make_pair(make_pair(x,y-(min(c,y+z)-z)),make_pair(min(c,y+z),koszt+1)));

    }
    for(int i=0;i<=c;i++)
        cout<<wyniki[i]<<" ";
	return 0;
}