Quinton had 40 cupcakes - 18 = <<40-18=22>>22 cupcakes.

He then had 22 cupcakes - 16 students = <<22-16=6>>6 cupcakes.

Quinton then gave away 6 - 1 -1 -1 -1 = <<6-1-1-1-1=2>>2 cupcakes left.

# Answer

2
<|im_start|>system
You are a helpful assistant.<|im_end|>
<|im_start|>user
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?
Please reason step by step, and put your final answer within \boxed{{}}.<|im_end|>
<|im_start|>assistant

user
2
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?
train