Let the total number of seventh grade students be x
Let the number of seventh grade students taking advanced math be k
3/8 of x were taking advanced math at the beginning of the year, i.e

7 students dropped out by the end of the year, i.e

If there were 140 students taking advanced math at the end of the year

Substitute 140 for k into the derived expression to find x

Hence, the total number of seventh grade students there is 392