Made Up

AtCoder
IDabc202_c
Time2000ms
Memory256MB
Difficulty
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$ [samples]
Samples
Input #1
3
1 2 2
3 1 2
2 3 2
Output #1
4

Four pairs satisfy the condition: $(1, 1), (1, 3), (2, 2), (3, 2)$.
Input #2
4
1 1 1 1
1 1 1 1
1 2 3 4
Output #2
16

All the pairs satisfy the condition.
Input #3
3
2 3 3
1 3 3
1 1 1
Output #3
0

No pair satisfies the condition.
API Response (JSON)
{
  "problem": {
    "name": "Made Up",
    "description": {
      "content": "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 ",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc202_c"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "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).\nHow ...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments