Under construction

Still being built. Things may change

Common Names

Interview

Time limit2sMemory limit256 MB

Summary
Given two lists of unique lowercase names, find and print the count and sorted list of names common to both.
Level

Easy3 of 10

Topics
Hash map, Sorting, String
Solved
No attempts yet

Problem

You are given two lists of names. The first list contains names of people not heard of, and the second list contains names of people not seen. Find the names that appear in both lists, sort them in lexicographic order, and print them.

Input

The first line contains two integers N and M, the number of names in the first and second lists.

The next N lines contain the names in the first list, one per line. The following M lines contain the names in the second list, one per line.

Each name consists only of lowercase English letters with no spaces, and its length is at most 20. N and M are positive integers not greater than 500,000.

No name appears more than once within the same list.

Output

Print the number of names that appear in both lists on the first line.

Then print those names in lexicographic order, one per line.

Examples1

  1. Example 1

    Input
    3 4
    ohhenrie
    charlie
    baesangwook
    obama
    baesangwook
    ohhenrie
    clinton
    
    Expected output
    2
    baesangwook
    ohhenrie