However, the Scanner class is slow and may cause a "timelimit exceeded". We can read the input faster with the BufferedReader class. The class "MyScanner" below uses a BufferedReader. The same method names as in the Scanner class have been chosen, e.g. to read the input as an integer we still can use nextInt().

and how it is working ? like — int a = sc.nextInt(); int b = sc.nextInt();

if i gave input 1 2 then how can this do like a = 1 and b = 2 ? every time i call nextInt() then it call next() in a new form. so how it can split the output and put those in different variable ? thanks in advance.