This problem was highlighted by #163. If we had many-to-many field for contest-problem relation, the solution would be much more elegant.