Chosing a ball from bucket have two outcomes -
1. ball has color i
2. ball does not have color i
For first bucket -
Probability that ball has ith color = (No of balls with ith color) / Total balls
for consecutive bucket k -
**Case1 - The ball added to bucket k had color i**
Probability that new ball taken out of bucket k has ith color = Probability that ball with ith color came out of previous bucket * (1 + count of balls with color ~~k in ith ~~i in kth bucket)/ (1 + Total balls in bucket k)
**Case2 - The ball added to bucket k did not had color i**
Probability that new ball taken out of bucket k has ith color
= (1 - Probability that ball with ith color came out of previous bucket) * (count of balls with color ~~k in ith ~~i in kth bucket)/ (1 + Total balls in bucket k)
Total probability = Case1 + case 2
Calculate this for each color for each bucket.
Solution - https://www.codechef.com/viewsolution/22129576