final solution for c++