#abc243b. B - Hit and Blow

B - Hit and Blow

Score : 200200 points

问题描述

给定两个整数序列,每个序列长度为 NN: A=(A1,A2,,AN)A = (A_1, A_2, \dots, A_N)B=(B1,B2,,BN)B = (B_1, B_2, \dots, B_N)

  • 序列 AA 中的所有元素互不相同。
  • 序列 BB 中的所有元素也同样互不相同。

请输出以下两个值:

  1. 在两个序列中同时出现且位置相同的整数个数。换言之,满足条件 Ai=BiA_i = B_i 的整数 ii 的个数。
  2. 在两个序列中同时出现但位置不同的整数个数。即,满足条件 Ai=BjA_i = B_jiji \neq j 的整数对 (i,j)(i, j) 的个数。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given integer sequences, each of length NN: A=(A1,A2,,AN)A = (A_1, A_2, \dots, A_N) and B=(B1,B2,,BN)B = (B_1, B_2, \dots, B_N).
All elements of AA are different. All elements of BB are different, too.

Print the following two values.

  1. The number of integers contained in both AA and BB, appearing at the same position in the two sequences. In other words, the number of integers ii such that Ai=BiA_i = B_i.
  2. The number of integers contained in both AA and BB, appearing at different positions in the two sequences. In other words, the number of pairs of integers (i,j)(i, j) such that Ai=BjA_i = B_j and iji \neq j.

Constraints

  • 1N10001 \leq N \leq 1000
  • 1Ai1091 \leq A_i \leq 10^9
  • 1Bi1091 \leq B_i \leq 10^9
  • A1,A2,,ANA_1, A_2, \dots, A_N are all different.
  • B1,B2,,BNB_1, B_2, \dots, B_N are all different.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 \dots ANA_N

B1B_1 B2B_2 \dots BNB_N

Output

Print the answers in two lines: the answer to1. in the first line, and the answer to2. in the second line.

Sample Input 1

4
1 3 5 2
2 3 1 4

Sample Output 1

1
2

There is one integer contained in both AA and BB, appearing at the same position in the two sequences: A2=B2=3A_2 = B_2 = 3.
There are two integers contained in both AA and BB, appearing at different positions in the two sequences: A1=B3=1A_1 = B_3 = 1 and A4=B1=2A_4 = B_1 = 2.

Sample Input 2

3
1 2 3
4 5 6

Sample Output 2

0
0

In both 1. and 2., no integer satisfies the condition.

Sample Input 3

7
4 8 1 7 9 5 6
3 5 1 7 8 2 6

Sample Output 3

3
2

update @ 2024/3/10 10:26:40