Stable fully linear time algorithm works
Remove unstable Python version