Manasa and Stones Problem from Hackerrank