Implemented solution to Codefroces : 267A