fixed algorithm in main-alt.cpp