시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 512 MB 37 3 3 8.108%

## 문제

There are $M$ boxes and $N$ balls. The balls are numbered $1$ through $N$, and the weight of the ball $i$ is $w_i$. You are also given a sequence $a_1, a_2, \ldots, a_K$. Each $a_j$ is an integer satisfying $1 \le a_j \le N$.

Initially, all the boxes are empty. For each $j = 1, 2, \ldots, K$ in this order, you have to perform the following operation:

• If one of the boxes contains the ball $a_j$, you do nothing. There is no cost for this operation.
• Otherwise, you choose one of the boxes and put the ball $a_j$ into the chosen box. However, if the chosen box already contains another ball, you should take that ball out of the box. The cost for this operation is $w_{a_j}$ (the cost doesn't depend on the box nor the ball you take out of the box).

Compute the minimum possible total cost of operations.

## 입력

The first line contains three integers $M$, $N$ and $K$ ($1 \le M \le 10$, $1 \le N, K \le 10^4$).

The $i$-th of the next $N$ lines contains an integer $w_i$ ($1 \le w_i \le 10^4$).

The $j$-th of the next $K$ lines contains an integer $a_j$ ($1 \le a_j \le N$).

## 출력

Print the minimum total cost.

## 예제 입력 1

3 3 6
10
20
30
1
2
3
1
2
3


## 예제 출력 1

60


## 예제 입력 2

2 3 6
10
20
30
1
2
3
1
2
3


## 예제 출력 2

80