OK it took a while and lots of ink, I couldn't resist. This is a trick question as far as I can see.
3 flatmates each pay £10 but are given £5 back. That means the 3 flatmates didn't pay £9 each, they paid £8.33 recurring.
What happens is they gain £1 back each which is £3 and the final £2 is given back. This is a separate equation.
So £8.33 recurring + £3 + £2 = £30 or there abouts
The £9.00 is not part of the equation but it does settle in your head and makes you think there is a quid missing.
Except they didnt - the recurring figure only comes into play when they get the £5 back not befor, the recurring figure is £10 which is what they put into the pot in the first place
Lets look at it from a different angle
The all put in £10 worth of £1 coins - total £30
The shopkeeper is in receipt of the £30
The shopkeeper returns 5 pound coins to the flatmates, off which they each take one coin so their total outlay is £9, since there is 3 of the the total spent is £27 and the balance of the £5 is left with the shopkeeper which is £2
:-)