import java.util.LinkedList; import java.util.Scanner; public class Main { private static Scanner cin; public static void main(String args[]) throws Exception { cin = new Scanner(System.in); int m = cin.nextInt(); Dictionary dic = new Dictionary(m);…