#P441. 【例77.2】经验值
【例77.2】经验值
Description
Xiaoming is playing a game. In this game, there is a permutation of numbers from to . We delete each number in a given order. Each time a number is deleted, Xiaoming gains experience points equal to the sum of the number to its left and the number to its right. Note that after deleting a number, the numbers on its left and right become directly connected. If there is no number on the left or right side, the experience gained from that side is .
Given the original permutation and the order in which Xiaoming deletes the numbers, please help calculate the total experience points Xiaoming will gain.
Input Format
The first line contains an integer ()
The second line contains integers, ,,..., representing the original permutation.
The third line contains integers, ,,...,; where represents the number that Xiaoming deletes in the -th step.
Output Format
Output a single line containing an integer, representing the answer.
Sample
3
1 2 3
3 1 24