102022: [AtCoder]ABC202 C - Made Up

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $300$ points

Problem Statement

Given are three sequences of length $N$ each: $A = (A_1, A_2, \dots, A_N)$, $B = (B_1, B_2, \dots, B_N)$, and $C = (C_1, C_2, \dots, C_N)$, consisting of integers between $1$ and $N$ (inclusive).

How many pairs $(i, j)$ of integers between $1$ and $N$ (inclusive) satisfy $A_i = B_{C_j}$?

Constraints

  • $1 \leq N \leq 10^5$
  • $1 \leq A_i, B_i, C_i \leq N$
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

$N$
$A_1$ $A_2$ $\ldots$ $A_N$
$B_1$ $B_2$ $\ldots$ $B_N$
$C_1$ $C_2$ $\ldots$ $C_N$

Output

Print the number of pairs $(i, j)$ such that $A_i = B_{C_j}$.


Sample Input 1

3
1 2 2
3 1 2
2 3 2

Sample Output 1

4

Four pairs satisfy the condition: $(1, 1), (1, 3), (2, 2), (3, 2)$.


Sample Input 2

4
1 1 1 1
1 1 1 1
1 2 3 4

Sample Output 2

16

All the pairs satisfy the condition.


Sample Input 3

3
2 3 3
1 3 3
1 1 1

Sample Output 3

0

No pair satisfies the condition.

Input

题意翻译

## 题目描述 [problemUrl]: https://atcoder.jp/contests/abc202/tasks/abc202_c 给出 3 个长度为 $N$ 的整数序列 $ A\ =\ (A_1,\ A_2,\ \dots,\ A_N),\ B\ =\ (B_1,\ B_2,\ \dots,\ B_N),\ C\ =\ (C_1,\ C_2,\ \dots,\ C_N) $ 求有多少个整数对 $ (i,\ j) $ 满足 $ A_i\ =\ B_{C_j} $ ## 输入格式 $ N $ $ A_1 $ $ A_2 $ $ \ldots $ $ A_N $ $ B_1 $ $ B_2 $ $ \ldots $ $ B_N $ $ C_1 $ $ C_2 $ $ \ldots $ $ C_N $ ## 输出格式 一个整数,表示答案 ## 样例 #1 ### 样例输入 #1 ``` 3 1 2 2 3 1 2 2 3 2 ``` ### 样例输出 #1 ``` 4 ``` ## 样例 #2 ### 样例输入 #2 ``` 4 1 1 1 1 1 1 1 1 1 2 3 4 ``` ### 样例输出 #2 ``` 16 ``` ## 样例 #3 ### 样例输入 #3 ``` 3 2 3 3 1 3 3 1 1 1 ``` ### 样例输出 #3 ``` 0 ``` ## 数据范围与提示 ### 数据范围 - $ 1\ \leq\ N\ \leq\ 10^5 $ - $ 1\ \leq\ A_i,\ B_i,\ C_i\ \leq\ N $ - 输入的均为整数 ### 样例解释 1 以下 4 个整数对满足条件 $ (1,\ 1),\ (1,\ 3),\ (2,\ 2),\ (3,\ 2) $ ### Sample Explanation 2 所有整数对都满足条件 ### Sample Explanation 3 不存在满足条件的整数对

加入题单

算法标签: