This page is still under construction.

Parts of this page are still being built. What you see may change.

Common Elements

Interview

Time limit2sMemory limit1024 MB

Summary
Given two short integer sequences, print every value that occurs in both, once each, in ascending order.
Level

Easy2 of 10

Topics
Hash map, Sorting, Implementation
Solved
No attempts yet

Problem

You are given an integer sequence A = (A1, A2, ..., AN) of length N and an integer sequence B = (B1, B2, ..., BM) of length M. Print every integer that appears in both A and B, each exactly once, in ascending order.

Input

The input is given from standard input in the following format.

N M
A1 A2 ... AN
B1 B2 ... BM

Output

Print every integer that appears in both A and B, each exactly once, in ascending order. Separate each integer with a newline.

Constraints

  • 1 ≦ N ≦ 100.
  • 1 ≦ M ≦ 100.
  • 1 ≦ Ai ≦ 100 (1 ≦ i ≦ N).
  • 1 ≦ Bj ≦ 100 (1 ≦ j ≦ M).

Examples4

  1. Example 1

    Input
    6 5
    2 4 6 8 10 12
    15 12 9 6 3
    
    Expected output
    6
    12
    
  2. Example 2

    Input
    3 5
    100 100 100
    100 100 100 100 100
    
    Expected output
    100
    
  3. Example 3

    Input
    1 1
    2
    5
    
    Expected output
  4. Example 4

    Input
    10 10
    76 91 98 7 98 7 98 10 63 91
    70 71 10 10 91 70 65 10 63 76
    
    Expected output
    10
    63
    76
    91