I. Golden Landmarks
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Graphic from visitgolden

The city of Golden has many landmarks worth visiting. Before arriving in Golden, you made a list of landmarks you want to visit and the order in which you will visit them. To understand where these landmarks are located, you create a map of Golden and mark each landmark on it. You determine the $$$x$$$ and $$$y$$$ coordinates of each landmark and plot out your journey for the day. Now, you want to determine the total walking distance required to visit all landmarks in the given order. You will start at the first landmark and finish your walk at the last landmark. Since Golden is laid out on a grid, the walking distance between two landmarks at coordinates $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$.

Input

The first line of input contains an integer $$$n$$$ ($$$ 2 \leq n \leq 10^5 $$$) representing the number of landmarks.

The next $$$n$$$ lines each contain a string $$$ s $$$ ($$$ 1 \leq |s| \leq 25 $$$), the name of a landmark, followed by two integers $$$x$$$ and $$$y$$$ ($$$ -10^4 \leq x, y \leq 10^4 $$$) representing the landmark's coordinates. Each landmark name consists only of uppercase and lowercase Latin letters and is unique.

The final line contains a space-separated sequence of $$$n$$$ landmark names, specifying the exact order in which you will visit them. Each landmark appears exactly once in this sequence.

Output

Output a single integer, the total walking distance required to visit all landmarks in the specified order.

Examples
Input
2
CTLM 1 1
MinesMarket 2 2
MinesMarket CTLM
Output
2
Input
5
ClearCreek 0 0
MinesM 20 10
SouthTable -20 -10
WoodysPizza 10 10
ColoradoSchoolOfMines 20 -10
ColoradoSchoolOfMines ClearCreek WoodysPizza SouthTable MinesM
Output
160