Reduce all the lower power of k to 0
for j in range ( idx , i , 1 ) : NEW_LINE INDENT p [ j ] = 0 NEW_LINE DEDENT idx = i + 1 NEW_LINE if ( p [ i ] == k ) : NEW_LINE p [ i ] = 0 NEW_LINE p [ i + 1 ] += 1 NEW_LINE j = len ( p ) - 1 NEW_LINE