first version (c++ and python)