problem can be outside contest
fix problem sort, extract complicated sorting logic out of controller