

from typing import *


def reconstructQueue(people: List[List[int]]) -> List[List[int]]:
    people.sort(key=lambda x: (x[0], x[1]))
    rtn = [None for _ in range(len(people))]
    for p in people:
        count, i = 0, 0
        while count < p[1]:
            if rtn[i] is None or rtn[i][0]==p[0]:
                count, i = count + 1, i + 1
            else:
                i += 1
        while rtn[i] != None:
            i += 1
        rtn[i] = p
    return rtn


if __name__ == '__main__':
    print(reconstructQueue([[7,0],[4,4],[7,1],[5,0],[6,1],[5,2]]))
