@@ -0,0 +1,2051 @@
+import java.io.BufferedReader;%0Aimport java.io.IOException;%0Aimport java.io.InputStreamReader;%0Aimport java.util.ArrayList;%0Aimport java.util.HashMap;%0Aimport java.util.List;%0Aimport java.util.Map;%0A%0Apublic class SparseArrays %7B%0A%0A    private static int readNumber(BufferedReader reader) throws IOException %7B%0A        String stringNumber = reader.readLine();%0A        return Integer.parseInt(stringNumber);%0A    %7D%0A%0A    private static Map%3CString, Integer%3E readStrings(BufferedReader reader, int numberOfStrings) throws IOException %7B%0A        Map%3CString, Integer%3E map = new HashMap%3C%3E(numberOfStrings);%0A        for (int i = 0; i %3C numberOfStrings; i++) %7B%0A            String string = reader.readLine();%0A            Integer occurrences = map.getOrDefault(string, 0);%0A            occurrences++;%0A            map.put(string, occurrences);%0A        %7D%0A        return map;%0A    %7D%0A%0A    private static List%3CString%3E readQueries(BufferedReader reader, int numberOfQueries) throws IOException %7B%0A        List%3CString%3E queries = new ArrayList%3C%3E(numberOfQueries);%0A        for (int i = 0; i %3C numberOfQueries; i++) %7B%0A            String query = reader.readLine();%0A            queries.add(query);%0A        %7D%0A        return queries;%0A    %7D%0A%0A    private static void printStringOccurrences(Map%3CString, Integer%3E stringsOccurrences, List%3CString%3E queries) %7B%0A        for (String query : queries) %7B%0A            Integer occurrences = stringsOccurrences.getOrDefault(query, 0);%0A            System.out.println(occurrences);%0A        %7D%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) %7B%0A            int numberOfStrings = readNumber(reader);%0A            Map%3CString, Integer%3E stringsOccurrences = readStrings(reader, numberOfStrings);%0A            int numberOfQueries = readNumber(reader);%0A            List%3CString%3E queries = readQueries(reader, numberOfQueries);%0A            printStringOccurrences(stringsOccurrences, queries);%0A        %7D catch (IOException e) %7B%0A            e.printStackTrace();%0A        %7D%0A    %7D%0A%7D%0A

Add solution for the SparseArrays problem.