Help me in solving PERMUT2 problem

My issue

My code

# cook your dish here
while True:
    n = int(input())
    permutation = list(map(int, input().split()))
    

Problem Link: PERMUT2 Problem - CodeChef