# Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

# Social Distancing

By Shafin · Limits 1s, 512 MB

The country of KhoaNali is structured as a giant road with $N (1 \leq N \leq 10^5)$ buildings on both sides, the northern buildings being houses and the southern buildings being workplaces. Each house has a unique label $h_i, (1 \leq h_i \leq N)$ and each workplace has a unique label $w_i, (1 \leq w_i \leq N)$

Person $x, (1 \leq x \leq N)$ lives in house $i$ and goes to work at workplace $j$ if $h_i = w_j = x$

Due to the recent NorocaVirus situation, everyone decided to distance himself from others. But due to the structure of KhoaNali, some of them may end up meeting someone else on their way. Your job is to find out the number of unordered pairs $(i, j)$ such that Person $i$ can meet Person $j$ on his way.

## Input

The first line contains an integer $N (1 \leq N \leq 10^5)$ — the number of buildings on each side of the road.

Second line contains $N$ integers $h_1, h_2, \dots , h_N$ — labels of the houses.

Third line contains $N$ integers $w_1, w_2, \dots , w_N$ — labels of the workplaces.

## Output

Print a single integer — the number of unordered pairs $(i, j)$ such that Person $i$ and Person $j$ can meet on their way.

## Sample

InputOutput
4
1 2 3 4
2 4 1 3

3 In the sample the pairs that can meet are $(1, 2), (1, 4)$ and $(3, 4)$

• DataStructure

### Statistics

76% Solution Ratio

EgorKulikovEarliest, Apr '20

EgorKulikovFastest, 0.0s

kzvd4729Lightest, 1.3 MB

kzvd4729Shortest, 537B

### Submit 