Quinton brought 40 cupcakes to school on his birthday. He gave a cupcake to each of the 18 students in Ms. Delmont's class. He also gave a cupcake to each of the 16 students in Mrs. Donnelly's class. He also gave a cupcake to Ms. Delmont, Mrs. Donnelly, the school nurse, and the school principal. How many cupcakes did he have left over?
Quinton had 40 cupcakes - 18 = 
<gadget id="calculator">40-18</gadget>
<output>22</output>
22 cupcakes.
He then had 22 cupcakes - 16 students = 
<gadget id="calculator">22-16</gadget>
<output>6</output>
6 cupcakes.
Quinton then gave away 6 - 1 -1 -1 -1 = 
<gadget id="calculator">6-1-1-1-1</gadget>
<output>2</output>
2 cupcakes left.

<result>2</result>