Getting TLE with scanner.nextInt()

I’m a beginner on codechef, I’m was solving CodeChef | Competitive Programming | Participate & Learn problem the other day, and I was getting TLE when I tried to take input from scanner nextInt method.

To summarise :

Scanner in = new Scanner(;
int n = in.nextInt(); // this gave TLE for some cases
int n = Integer.parseInt(; // this worked for some reason