Implementation of KPM algorithm in C++