Under construction

Still being built. Things may change

Volunteers

Time limit1sMemory limit1024 MB

Summary
Given two supervision trees over n volunteers, count for each scientific member how many technical members can share a volunteer with it, and report the total.
Level

Hard8 of 10

Topics
Tree, DFS, Segment tree
Solved
No attempts yet

Problem

A large number of androids take part in the interplanetary informatics olympiad. Androids who devise problems, write statements, and develop test sets are members of the scientific committee. Androids who keep the computers and the software installed on them working are members of the technical committee. A third large group, the volunteers, helps organize and run many other events.

Each volunteer has one direct supervisor in the scientific committee and one direct supervisor in the technical committee. Every member of the scientific committee except its chair has a direct supervisor who is another member of the scientific committee. Every member of the technical committee except its chair also has a direct supervisor, and that supervisor is a member of the technical committee.

At the start of the olympiad, a process assigns supervisors to all volunteers, scientific committee members, and technical committee members. It works as follows.

All n volunteers receive unique numbers from 1 to n and line up in increasing order of their numbers. Then m scientific committee members, also numbered uniquely from 1 to m, choose their subordinates one by one in increasing order of their numbers. First, member 1 chooses some volunteers who are standing consecutively in the line. The chosen volunteers leave the line, and member 1 steps into the line at the place where they stood, replacing several androids at once. Then member 2 chooses subordinates from those now in the line and replaces them in the same way. The process continues, and each later member may choose as subordinates any volunteers and scientific committee members currently in the line. Last, the chair of the scientific committee chooses all androids still in the line.

When only the chair of the scientific committee remains in the line, the same process repeats from the beginning, now with the members of the technical committee. The volunteer numbers stay the same, and the volunteers line up in the same order as in the scientific committee selection.

A scientific committee member may conflict with a technical committee member if the same volunteer is a subordinate of both, directly or indirectly. By this definition, the chair of the scientific committee can always conflict with the chair of the technical committee. The total number of possible conflicts determines how well the olympiad is run.

Write a program that counts, for each member of the scientific committee, the number of technical committee members it may conflict with, and computes the total of these conflicts.

Input

The first line contains the integers n, m, and k (1≤n,m,k≤1000001 \le n, m, k \le 100000): the number of volunteers, members of the scientific committee, and members of the technical committee.

Each of the next n lines contains two integers a_i and b_i (1≤ai≤m1 \le a_i \le m, 1≤bi≤k1 \le b_i \le k): the number of the scientific committee member who supervises the i-th volunteer, and the number of the technical committee member who supervises that volunteer.

The next line contains m-1 integers c_i (i=0,1,…,m−1i = 0, 1, \ldots, m-1, i<ci≤mi < c_i \le m): the number of the direct supervisor of the i-th member of the scientific committee. The chair of the scientific committee is member m.

The next line contains k-1 integers d_i (i=0,1,…,k−1i = 0, 1, \ldots, k-1, i<di≤ki < d_i \le k): the number of the direct supervisor of the i-th member of the technical committee. The chair of the technical committee is member k.

It is guaranteed that all input data is correct, meaning it results from the subordinate assignment process described above.

Output

The first line of the output contains one number: the total number of conflicts.

Hint

In the sample, only the second member of the scientific committee and the second member of the technical committee cannot conflict with each other.

Examples1

  1. Example 1

    Input
    4 3 4
    1 2
    1 1
    2 1
    2 4
    3 3
    3 3 4
    
    Expected output
    11