def get_failure_rate(n, stages):
    failure = []
    total_players = len(stages)
    
    for stage in range(1, n + 1):
        fail_count = stages.count(stage)
        if total_players == 0:
            fail_rate = 0
        else:
            fail_rate = fail_count / total_players
        failure.append((stage, fail_rate))
        total_players -= fail_count
    
    failure.sort(key=lambda x: (-x[1], x[0]))
    
    return [stage for stage, rate in failure]

n = 5
stages = [2, 1, 2, 6, 2, 4, 3, 3]
ret = get_failure_rate(n, stages)
print(ret)  # [3, 4, 2, 1, 5]

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: