import sys #input = sys.stdin.readline input = sys.stdin.buffer.readline from heapq import heapify, heappop, heappush def main(): N,M,X = map(int,input().split()) A = []; B = [] not_used = []; used = [] for _ in range(N): a,b = map(int,input().split()) A.append(a) B.append(b) heappush(not_used,(-a,b)) #値、組 K = int(input()) C = list(map(int,input().split())) dic = {} for c in C: if c in dic: dic[c] += 1 else: dic[c] = 1 L = [] used_group = set([]) score = 0 ans = 0 for i in range(N): if used: a,b = heappop(used) val_used_group = (-a,b) else: val_used_group = (0,0) #dummy val_not_group = (0,0) #dummy while not_used: a,b = heappop(not_used) a *= -1 #正に値に直す #print(a,b) #print("VAL",val_used_group) if b not in used_group: val_not_group = (a,b) break else: if val_used_group[0] > a: #既に出した値が同じ組中で最高 heappush(used,(-a,b)) else: temp = (a,b) val_used_group, temp = temp, val_used_group a,b = temp heappush(used,(-a,b)) #print(val_used_group,val_not_group) if val_used_group == (0,0): L.append(val_not_group) used_group.add(val_not_group[1]) score += val_not_group[0] + X elif val_not_group == (0,0): L.append(val_used_group) used_group.add(val_used_group[1]) score += val_used_group[0] else: score_used = score + val_used_group[0] socre_not = score + val_not_group[0] + X #1組増えるので if score_used > socre_not: #使用済みのグループを使う。 score = score_used L.append(val_used_group) used_group.add(val_used_group[1]) heappush(not_used,(-val_not_group[0],val_not_group[1])) else: score = socre_not L.append(val_not_group) used_group.add(val_not_group[1]) heappush(used, (-val_used_group[0],val_used_group[1])) #print(score) if i+1 in dic: ans += score*dic[i+1] #print(L) print(ans) if __name__ == '__main__': main()