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.
#### 2