Single threaded solution and a simple code to verify the result file