Let n be a fixed integer. Kostya has a black box, such that if you put in exactly 2n+1 coins of distinct weights, the box will expose the coin of median weight. The teacher gave Kostya 4n+1 coins of distinct weights and told him which coin has the median weight.

Can Kostya check whether the teacher is right, using the box not more than n+2 times?

First let M be the median chosen by the teacher. Choose another 2n coins to go with M. We will call this collection of coins the "blue bag" (Leaving behind 2n coins in a "red" bag)

Test if M is the median of this set of 2n+1 coins in the blue bag.

If it isn't, swap the actual median of this blue bag of 2n+1 coins with a coin from the red bag.

Keep repeating this process up to the nth use of the box.

If M has never been the median of the blue box for these tests, then M is not the median.

Otherwise, M has been the median of a set of 2n+1 coins, and we still have at least one more test with the box at least. Now we take M from the blue bag and put it with the red bag. We then put the red bag of 2n+1 coins to the test. If M is also the median of the red bag, then M is truely the median of the whole set. If not, then M is not the median of the set.