At a certain dance class, each student must pick exactly one partner. Each pair of dancers must consist of one advanced student and one beginner student. At first, after everyone pairs up, there are 4 extra beginner students. Then, after half of the beginner students have left, there are 5 extra advanced students. How many advanced students are in the class?

To solve this problem, let's denote the number of advanced students as "A" and the number of beginner students as "B."

Given that there are 4 extra beginner students initially, we can write the equation:
B - A = 4 (Equation 1)

After half of the beginner students leave, the number of beginner students becomes B/2. Similarly, the number of advanced students increases by 5. So we can write the equation:
B/2 + 5 = A (Equation 2)

To solve this system of equations, we can substitute the value of B from Equation 1 into Equation 2.

Substituting B = A - 4 into Equation 2:
(A - 4)/2 + 5 = A

Simplifying the equation:
(A - 4) + 10 = 2A

Combining like terms:
A + 6 = 2A

Subtracting A from both sides:
6 = A

Therefore, the number of advanced students in the class is 6.