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

int maksA, maksB, maksC, A, B, C, wyniki[500000];
string ABC;
queue<int> qA, qB, qC, deep;
map <string,int> mapa;


bool przelanie(int a, int b, int maks)
{
    if(a+b>maks)
        return 0;
    else
        return 1;
}

void kolejka(int qA1, int qB1, int qC1, int maks, int deep1)
{
    ABC= to_string(qA1) + "#" + to_string(qB1) + "#" + to_string(qC1);
    if(mapa[ABC]==0)
    {
        mapa[ABC]=1;
        qA.push(qA1);
        qB.push(qB1);
        qC.push(qC1);
        deep.push(deep1+1);
    }
}


int main ()
{
    cin>>maksA>>maksB>>maksC;
    cin>>A>>B>>C;
    for(int i=0; i<=maksC; i++)
    {
        wyniki[i]=-1;
    }
    cout<<ABC;
    qA.push(A);
    qB.push(B);
    qC.push(C);
    deep.push(0);
    while (!qA.empty()&&!qB.empty()&&!qC.empty())
    {
        //cout<<deep.front()<<" "<<qA.front()<<endl;
        if(wyniki[qA.front()]==-1)
            wyniki[qA.front()]=deep.front();
        if(wyniki[qB.front()]==-1)
            wyniki[qB.front()]=deep.front();
        if(wyniki[qC.front()]==-1)
            wyniki[qC.front()]=deep.front();
        if(przelanie(qA.front(),qB.front(),maksB))
        {
            kolejka(0,qB.front()+qA.front(), qC.front(), maksB, deep.front());
        }
        else
        {
            kolejka(qA.front()-(maksB-qB.front()),maksB, qC.front(), maksB, deep.front());
        }
        if(przelanie(qA.front(),qC.front(),maksC))
        {
            kolejka(0,qB.front(), qC.front()+qA.front(), maksC, deep.front());
        }
        else
        {
            kolejka(qA.front()-(maksC-qC.front()),qB.front(), maksC, maksC, deep.front());
        }
        if(przelanie(qB.front(),qA.front(),maksA))
        {
            kolejka(qA.front()+qB.front(),0, qC.front(), maksA, deep.front());
        }
        else
        {
            kolejka(maksA, qB.front()-(maksA-qA.front()), qC.front(), maksA, deep.front());
        }
        if(przelanie(qB.front(),qC.front(),maksC))
        {
            kolejka(qA.front(),0, qC.front()+qB.front(), maksC, deep.front());
        }
        else
        {
            kolejka(qA.front(),qB.front()-(maksC-qC.front()), maksC, maksC, deep.front());
        }
        if(przelanie(qC.front(),qA.front(),maksA))
        {
            kolejka(qA.front()+qC.front(),qB.front(),0, maksA, deep.front());
        }
        else
        {
            kolejka(maksA,qB.front(),qC.front()-(maksA-qA.front()), maksA, deep.front());
        }
        if(przelanie(qC.front(),qB.front(),maksB))
        {
            kolejka(qA.front(),qB.front()+qC.front(),0, maksB, deep.front());
        }
        else
        {
            kolejka(qA.front(),maksB,qC.front()-(maksB-qB.front()), maksB, deep.front());
        }

        qA.pop();
        qB.pop();
        qC.pop();
        deep.pop();

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