2nd solution fully done