冒泡思想 还是比较简单的
def soul(nums):
help=list()
help.append(nums.pop())
while len(nums)!=0:
cur=nums.pop()
if cur<=help[-1]:
help.append(cur)
else:
while len(help)!=0 and cur>help[-1]:
nums.append(help.pop())
help.append(cur)
return help
n=map(int ,input())
nums=list(map(int ,input().split()))
res=soul(nums)
print(" ".join(map(str,res)))