added a solution, need to port to C and make more efficient for other large input