I'm getting TLE in Biased Standings (https://www.spoj.pl/problems/BAISED/). According to the list of best solutions, it is possible to solve in Python.
My solution is greedy, I sort the list of ranks and then use it to compute the minimal badness. I tried using cStringIO to buffer input, but apparently that is still not enough. The code is so simple that I cannot think of any other obvious places to optimize. Can someone please share some speed tips for this one?