All the code needed to prove LONSC algorithm