Limits 1s, 512 MB

The country of KhoaNali is structured as a giant road with NN buildings on both sides, the northern buildings being houses and the southern buildings being workplaces. Each house has a unique label hih_i and each workplace has a unique label wiw_i.

Person xx (1xN1 \leq x \leq N) lives in house ii and goes to work at workplace jj if hi=wj=xh_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)(i, j) such that Person ii can meet Person jj on his way.

Input

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

Second line contains NN integers h1,h2,,hNh_1, h_2, \dots , h_N (1hiN1 \leq h_i \leq N) — labels of the houses.

Third line contains NN integers w1,w2,,wNw_1, w_2, \dots , w_N (1wiN1 \leq w_i \leq N) — labels of the workplaces.

Output

Print a single integer — the number of unordered pairs (i,j)(i, j) such that Person ii and Person jj 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, 2), (1,4)(1, 4), and (3,4)(3, 4).


Submit

Login to submit.

Statistics

75% Solution Ratio
EgorKulikovEarliest, Apr '20
FrdhsnFastest, 0.0s
FrdhsnLightest, 6.3 kB
kzvd4729Shortest, 537B
Toph uses cookies. By continuing you agree to our Cookie Policy.