Submitting an official solution before solving the problem yourself is a bannable offence.
It suffices to count inversions by iterating over all pairs of indices (including ).
Optimize the subtask solution by iterating over all pairs of indices excluding .
This subtask was intended to reward solutions that use a heuristic that has a bad query constant.
First, query heights. If there are more queries than people, output the permutation.
For the heights that were not found in the queries, insert them into an array and sort it with any built-in function but create a custom comparator to interact with the grader.
After sorting it, output the permutation.
Note that other solutions that use probabilistic lemmas also suffice since the grader is not adaptive.