import heapq
def solution(priorities, location):
answer = 0
a = []
for i in range(len(priorities)):
a.append((-priorities[i], i))
while True:
b = a[:]
heapq.heapify(b)
if a[0][0] > b[0][0]:
temp2 = a[0]
a = a[1:]
a.append(temp2)
else:
temp = a[0]
answer += 1
a = a[1:]
if temp[1] == location:
break
return answer