C++ Solution