R9 Found at last problem

Wrong answer for 3rd test-case, first two test cases passed. Code: https://ide.codingblocks.com/s/69470

Done with it. Got the error and corrected it.