algo for python, C++