C++ implementation of 5_6