There were 40 more girls than boys in the school hall. 2/5 of the girls and 1/3 of the boys left the hall. In the end, there were 18 more girls than boys remaining in the hall. Find the total number of girls and boys in the hall at first.

Let the number of boys be x

girls=x+40

girls left the hall= 2/5(x+40)= 2/5x+16
boys left the hall= 1/3x

girls remained in the hall= x+40-(2/5x+16)
=x+40-2/5x-16
=3/5x+24

boys remained in the hall= x-1/3x=2/3x

3/5x+24=2/3x+18
24-18=2/3x-3/5x
6=1/15x
x=6×15
x=90

boys=90
girls=90+40=130
total=90+130=220