pythondef solve(N, PS):
ret = []
used = [False] * (N - 1)
def swap(x):
PS[x - 1], PS[x] = PS[x], PS[x - 1]
used[x - 1] = True
ret.append(x)
for target in range(1, N):
x = PS.index(target, target - 1)
for i in range(x, target - 1, -1):
if used[i - 1]:
return [-1]
swap(i)
if False in used:
return [-1]
return ret