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

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define debug std::cout << "hmm" << std::endl;
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;
typedef std::vector<int> vi;
typedef std::vector<ll> vl;

template <typename T>
void print(const T &t)
{
    std::cout << t << ' ';
}
template <typename T1, typename T2>
void print(const std::pair<T1, T2> &t)
{
    std::cout << '{' << t.first << ' ' << t.second << '}';
}
template <typename T>
void print(const std::vector<T> &t)
{
    for (auto a : t)
        print(a);
    std::cout << std::endl;
}

struct triplet
{
    int a, b, c;
    triplet() {}
    triplet(int t_a, int t_b, int t_c) { a = t_a, b = t_b, c = t_c; }
    int &operator[](int i)
    {
        switch (i)
        {
        case 0:
            return a;
            break;
        case 1:
            return b;
            break;
        case 2:
            return c;
        default:
            throw std::exception();
            break;
        }
    }
    int size() { return 3; }
    void print()
    {
        std::cout << '{' << a << ' ' << b << ' ' << c << '}' << std::endl;
    }
};

bool operator<(const triplet &a, const triplet &b)
{
    if (a.a == b.a)
        return pii{a.b, a.c} < pii{b.b, b.c};
    return a.a < b.a;
}

main()
{
    std::cin.tie(0)->sync_with_stdio(0);
    std::cin.exceptions(std::cin.failbit);

    int Z = 1;
    //std::cin >> Z;
    while (Z--)
    {
        triplet MAX, NUM;
        for (int i = 0; i < 3; i++)
            std::cin >> MAX[i];
        for (int i = 0; i < 3; i++)
            std::cin >> NUM[i];
        std::queue<std::pair<triplet, int>> Q;
        std::set<triplet> S;
        vi V(MAX[2] + 1, -1);
        Q.push({NUM, 0});
        while (Q.size())
        {
            //Q.front().first.print();
            if (S.find(Q.front().first) == S.end())
            {
                S.insert(Q.front().first);
                for (int i = 0; i < 3; i++)
                    if (V[Q.front().first[i]] < 0)
                        V[Q.front().first[i]] = Q.front().second;
                auto T = Q.front().first;
                int temp;
                temp = std::min(T[0], MAX[1] - T[1]);
                Q.push({triplet(T[0] - temp, T[1] + temp, T[2]), Q.front().second + 1});
                temp = std::min(T[0], MAX[2] - T[2]);
                Q.push({triplet(T[0] - temp, T[1], T[2] + temp), Q.front().second + 1});
                temp = std::min(T[1], MAX[0] - T[0]);
                Q.push({triplet(T[0] + temp, T[1] - temp, T[2]), Q.front().second + 1});
                temp = std::min(T[1], MAX[2] - T[2]);
                Q.push({triplet(T[0], T[1] - temp, T[2] + temp), Q.front().second + 1});
                temp = std::min(T[2], MAX[0] - T[0]);
                Q.push({triplet(T[0] + temp, T[1], T[2] - temp), Q.front().second + 1});
                temp = std::min(T[2], MAX[1] - T[1]);
                Q.push({triplet(T[0], T[1] + temp, T[2] - temp), Q.front().second + 1});
            }
            Q.pop();
        }
        print(V);
    }
}