Answer:
We can solve this problem by using the information provided in the riddle to create a system of equations. Let x be the number of pencils that were originally in the box. We can then create the following equations:
x < 40
x - 4 = 2
x - 3 = 0
x - 5 = 0
We can then solve this system of equations to find the value of x. First, we note that the second and third equations imply that x is equal to 3 or 5. Substituting these values into the first equation, we find that x cannot be 3, as this would violate the inequality. However, x can be 5, as 5 is less than 40. Therefore, the number of pencils that were originally in the box is 5.