Also, you shouldn’t use Scanner. It’s very slow in taking input. Use InputStreamReader and BufferedReader. Your class name doesn’t need to be Main if it’s not public. This way you can have multiple codechef problem solutions organized in one folder.
Welcome to CodeChef and be patient in your endeavours, CodeChef problems can be frustrating sometimes. Check out the Editorials for that problem which you can’t solve.