Three naughty boys stole some mangoes from a garden. As it was late in the evening, they decided to divide the fruit equally among them in the morning, and went to sleep.
At night while the other two were sleeping, one boy woke up, tip-toed to the basket of mangoes, counted them and ate one. From the remainder he took a precise third and went back to sleep.
After some time a second boy woke up. He counted the mangoes, at one, took an exact third of the remaining and went back to sleep.
A little before sun rise the third boy also woke up, ate one, and like the other two boys took a precise third of the remainder in whole mangoes.
In the morning, all the three boys went together to the basket of mangoes, counted them. Amongst them they found one which was over ripe—almost rotten. They threw it away. From the remainder they made an exact division.
How many mangoes in all did they steal?