My code gives the correct output of the sample input. However, it cannot pass the verification. Can anyone tell me the reason?
package com.codegym.task.task07.task0720;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Scanner;
/*
Shuffled just in time
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
//write your code here
ArrayList<String> list = new ArrayList<String> ();
Scanner scanner = new Scanner (System.in);
int N = scanner.nextInt();
int M = scanner.nextInt();
for (int i=0; i<N+1; i++) list.add(scanner.nextLine());
for (int i=1; i<M+1; i++) {
String str = list.get(1);
list.add(str);
list.remove(1);
}
for (int i=1; i<N+1; i++) System.out.println(list.get(i));
}
}