t=input()z=0for i,e in enumerate(t): if e: while z:t[i-z]=e+z if l>e else e-z;z-=1 l=e else:z+=1print t
[1, 0, 0, 0, 5, 6, 0, 4, 0, 0, 1]
[1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1]
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!