Boxes and Balls

아직 제출이 없습니다시간 제한1초메모리 제한512 MB

문제

There are MM boxes and NN balls. The balls are numbered 11 through NN, and the weight of the ball ii is w_iw\_i. You are also given a sequence a_1,a_2,,a_Ka\_1, a\_2, \ldots, a\_K. Each a_ja\_j is an integer satisfying 1a_jN1 \le a\_j \le N.

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

  • If one of the boxes contains the ball a_ja\_j, you do nothing. There is no cost for this operation.
  • Otherwise, you choose one of the boxes and put the ball a_ja\_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_jw\_{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 MM, NN and KK (1M101 \le M \le 10, 1N,K1041 \le N, K \le 10^4).

The ii-th of the next NN lines contains an integer w_iw\_i (1w_i1041 \le w\_i \le 10^4).

The jj-th of the next KK lines contains an integer a_ja\_j (1a_jN1 \le a\_j \le N).

출력

Print the minimum total cost.