P26525 [AtCoder] Common Elements
提高-
题目描述

Problem Description

Given an integer sequence \( A = (A_1, A_2, \ldots, A_N) \) of length \( N \) and an integer sequence \( B = (B_1, B_2, \ldots, B_M) \) of length \( M \), output all integers that appear in both \( A \) and \( B \) in ascending order, one per line.

Input Format

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

\( N \) \( M \) \( A_1 \) \( A_2 \) \( \ldots \) \( A_N \) \( B_1 \) \( B_2 \) \( \ldots \) \( B_M \)

Output Format

Output all integers that appear in both \( A \) and \( B \) in ascending order, one per line.

Sample Input and Output

Sample Input #1

6 5
2 4 6 8 10 12
15 12 9 6 3

Sample Output #1

6
12

Sample Input #2

3 5
100 100 100
100 100 100 100 100

Sample Output #2

100

Sample Input #3

1 1
2
5

Sample Output #3


Sample Input #4

10 10
76 91 98 7 98 7 98 10 63 91
70 71 10 10 91 70 65 10 63 76

Sample Output #4

10
63
76
91

Notes/Hints

Constraints

  • \( 1 \leq N \leq 100 \).
  • \( 1 \leq M \leq 100 \).
  • \( 1 \leq A_i \leq 100 \) (\( 1 \leq i \leq N \)).
  • \( 1 \leq B_j \leq 100 \) (\( 1 \leq j \leq M \)).

Sample Explanation 1

6 appears at the 3rd position in \( A \) and the 4th position in \( B \). Also, 12 appears at the 6th position in \( A \) and the 2nd position in \( B \). No other integers appear in both \( A \) and \( B \). Therefore, output 6 and 12 in ascending order, each on a new line.

Sample Explanation 2

100 appears in both \( A \) and \( B \). No other integers appear in \( A \) and \( B \). Therefore, output 100.

Sample Explanation 3

No integers appear in both \( A \) and \( B \). Therefore, output nothing.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
6 5 2 4 6 8 10 12 15 12 9 6 3
样例输出
6 12