n = int(input()) def next_permutation(lst): n = len(lst) i = n - 1 while i > 0 and lst[i - 1] >= lst[i]: i -= 1 if i