First, multiply $3 by 4 to get $12 spent on cookies. Then, you multiply $12 by 2 to know that the pies cost $24. You then divide the $24 by 3 to get $6 per pie. Meaning, each pie had cost $6. You add the $12 and $24 together to get $36. Finally, you subtract $36 from $40 to know that she only has $4 left.