updated c++ solution