'''
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
'''
def solve(arr):
if not arr:
return []
tmp = []
ret = []
for x in arr:
if not ret or ret[-1] < x:
ret.append(x)
else:
tmp.append(x)
return ret + solve(tmp)
print(solve([0,0,1,1,1,2,2,3,3,4]))
print(solve([2,2,3,4,4]))