Mr. Singsong distributed out 4 bags to Allan, Brian, Charlie and David. He said: Each of you have a bag of red and/or white balls. Every bag has 3 balls. The numbers of red balls in all bags are different. Even each bag has a label to indicate what each bag contains, all labels are completely wrong. Now, you can take out 2 balls out from the bag and then tell me what is the color of the third ball.

Allan took out 2 red balls from his bag. After he compared the label he told Mr. Singsong what the color of the third ball was immediately.

Brian took out 1 red ball and 1 white ball from his bag. After he compared the label he told Mr. Singsong what the color of the third ball was immediately also.

Charlie took out 2 white balls from his bag. After he compared the label, he could not tell what color of the third ball was.

However, David said to Mr. Singsong: I can tell what color of all my 3 balls are. He did it correctly. But how?

Also, can you tell what label said and what kind of balls each person had?

Allan's bag seems to be quite easy.He has got 2 red balls.So the third ball depends on the label. If the label says there are 3 red balls, then he will get the third ball as white.If it says that there are 2 red and a white ball then the third ball should be a red ball.These are the only cases as Allan is able to say the third ball.

In case of Brian, he has got a red ball and a white ball.So his bag's label should tell him that 2 red or white balls are there.So he has chosen the opposite ball and told it immediately.

Since Charlie has taken out 2 white balls and could not say the answer, the label should say that there must betwo red and a white or three red.

Now it's the turn of David.He guessed all of his three balls correctly.He had made it even without seeing the two balls.So the only chance of doing it is by using the constraint The numbers of red balls in all bags are different.

By this we can reduce the possibilities.Allan got 2 red for sure.Brian got 1 red for sure.Charlie may or may not have 1 redDavid's case, a big question mark.

Since Charlie could not answer, the chance of having 1 red ball should be there.So Brian don't have only 1 red,but 2.Since Brian got 2 red,Allan should have different number.So he should got 3 red.

Now for the last two guys,we should take that,if there is a presence of red ball, the number of white balls are also different.

Allan had red balls and the total of his white ball is zero.Brian got 1 white.This makes that 0 and 1 case of white is ruled out.Now Charlie got 2 white for sure.So his chance is either 1 red or 0 red.Since there is already 0 red,he should got 1 red.

A got 2 red balls -> either he has c3 or c4. As the label is incorrect but he can tell immediately, it should be l4 or l3 respectively.(i.e "l4 when c3" or "l3 when c4")

B got 1 red, 1 white balls -> either he has c2 or c3. As the label is incorrect but he can tell immediately, it should be l3 or l2 respectively.

C got 2 white balls -> either he has c1 or c2. As the label is incorrect but he can't tell immediately, it should be l3 or l4.

Now, that leaves D with l1. As the label is incorrect, that implies C has combination c1.Also B must have label l2 then which means his combination is c3.So, A must have combination c4 then which means his label is l3.Thus, D has combination c2 and C has label l4.