Let us denote by aX, aY and aZ the numbers of cakes of type A received by X, Y and Z respectively, and by bX, bY and bZ the numbers of cakes of type B received by X, Y and Z, respectively. Then, they are non-negative integers and they satisfy aX+aY+aZ=bX+bY+bZ=24.
If aX<aY, then by the condition specified for the problem, we must have either bX>bY or aX+bX≥aY+bY. We note that even when the second alternative takes place, we must have bX>bY, since aX<aY. So, we must have the following implication: ⌈aX<aY⌉⇒⌈bX>bY⌉. Arguing similarly, we see that in order for the condition of the problem to be satisfied, we must also have the following implications as well: ⌈aX>aY⌉⇒⌈bX<bY⌉, ⌈bX<bY⌉⇒⌈aX>aY⌉, ⌈bX>bY⌉⇒⌈aX<aY⌉. We therefore conclude that in order for the condition of the problem to be satisfied for X and Y, we need one of the following conditions to be satisfied:
* aX<aY and bX>bY,
* aX=aY and bX=bY,
* aX>aY and bX<bY.
Conversely, if one of these conditions is satisfied, then we see the condition of the problem is satisfied for X and Y. Similar statements can be made for X and Z, and for Y and Z, which guarantee the validity of the condition of the problem for the corresponding pairs.
The number of triples (x,y,z) of non-negative integers satisfying x+y+z=24 is given by
(226)=2×126×25=325.
We classify them further according to the relative order of x,y,z.
* When x=y=z is satisfied: there is only one triple (x,y,z)=(8,8,8) in this case.
* When x=y<z is satisfied: in this case, we can write (x,y,z)=(k,k,24−2k), where k is an integer satisfying 0≤k≤7. So, there are 8 such triples. The same result holds for the cases y=z<x, z=x<y.
* When x=y>z is satisfied: in this case, we have (x,y,z)=(k,k,24−2k), where k is an integer satisfying 9≤k≤12. So, there are 4 such triples. The same result holds for the cases y=z>x, z=x>y.
* The remaining case: We have x,y,z to be distinct in this case, and there are 325−1−8×3−4×3=288 such triples (x,y,z). There are 6 possibilities for the order of x,y,z, but by symmetry, we can conclude that the number of those triples (x,y,z) with x<y<z is 6288=48, and the same result holds for others.
In order to get the solution for the problem, we count the number of cases depending on the order relation among aX,aY,aZ.
* When aX=aY=aZ: in this case, we must have bX=bY=bZ, so we have only 1×1=1 possibility.
* When aX=aY<aZ: in this case, we have to have bX=bY>bZ, so we have 8×4=32 possibilities. The same result holds for the cases aY=aZ<aX and aZ=aX<aY.
* When aX=aY>aZ: in this case, we have to have bX=bY<bZ, so we have 4×8=32 possibilities. The same result holds for the cases aY=aZ>aX and aZ=aX>aY.
* When aX<aY<aZ: in this case, we have to have bX>bY>bZ, so we have 48×48=2304 possibilities. The same result holds for the five other cases, where aX,aY,aZ are all distinct.
Summing up all these numbers of possibilities, we obtain that the number of ways to distribute cakes among X, Y, Z to satisfy the condition of the problem is
1×1+32×3+32×3+2304×6=14017.