Little Billy was out trick or treating on Halloween. He had gotten a lot of candy and was peering into his bag, when out from behind a tree came Freddy Krueger. Freddy reached into Billy's bag and took half of his candy plus one piece. Within a few steps, Billy encountered a Great White Shark, who reached into Billy's sack and took half of his remaining candy plus two pieces. Before Billy could turn and run, a Ninja Turtle, stole half of the candy that was left plus three pieces. Now Little Billy began to cry because he only had 5 pieces of candy left. How many pieces of candy did Billy have before Freddy, the Shark, and the Ninja Turtle raided his sack?

Let Billy have n pieces of candy. Tallying up all the thefts, we get

After Freddy, Billy has n - (n/2 + 1) = n/2 - 1

After Shark, Billy has n/2 - 1 - (n/2 - 1)/2 - 2 = n/4 - 5/2

After Turtle, Billy has n/4 - 5/2 - (n/4 - 5/2)/2 - 3 = n/8 - 17/4

n/8 - 17/4 = 5
n - 34 = 40
n = 74

Billy had 74 pieces
So, Freddy took 37+1 leaving 36
Shark took 18+2 leaving 16
Turtle took 8+3 leaving 5

working from the other end,

n = 2(2(2(5+3)+2)+1) = 74

To find out how many pieces of candy Billy had before Freddy, the Shark, and the Ninja Turtle took some, we can work backwards.

We know that Billy ended up with 5 pieces of candy left, and we want to figure out how many pieces he had before any were taken.

Let's start by undoing what the Ninja Turtle did. The Ninja Turtle took half of whatever was left, plus three pieces. So, if Billy has 5 pieces left, we can imagine giving back the three pieces that the Ninja Turtle took, and then doubling the candy to get back to the original amount.

5 + 3 = 8 (Pieces before the Ninja Turtle took some)
8 x 2 = 16 (Original number of pieces before the Turtle took 8 pieces)

Now, let's undo what the Shark did. The Shark took half of what was left, plus two pieces. So, if Billy had 16 pieces, we can imagine giving back the two pieces that the Shark took, and then doubling the candy to get back to the original amount.

16 + 2 = 18 (Pieces before the Shark took some)
18 x 2 = 36 (Original number of pieces before the Shark took 8 pieces)

Finally, let's undo what Freddy did. Freddy took half of what was left, plus one piece. So, if Billy had 36 pieces, we can imagine giving back the one piece that Freddy took, and then doubling the candy to get back to the original amount.

36 + 1 = 37 (Pieces before Freddy took some)
37 x 2 = 74 (Original number of pieces before Freddy took 18 pieces)

Therefore, Little Billy had 74 pieces of candy before Freddy, the Shark, and the Ninja Turtle raided his sack.