mod = 1000000007 eps = 10**-9 def main(): import sys from heapq import heappush, heappop input = sys.stdin.buffer.readline N, M, X = map(int, input().split()) AB = [] best = [-1] * (M+1) best_idx = [-1] * (M+1) for i in range(N): a, b = map(int, input().split()) if a > best[b]: best[b] = a best_idx[b] = i AB.append((a, b)) pq_unseen = [10 ** 15] pq_seen = [10 ** 15] used = set() for j in range(1, M+1): if best_idx[j] != -1: heappush(pq_unseen, -best[j]) used.add(best_idx[j]) for i in range(N): a, b = AB[i] if i not in used: heappush(pq_seen, -a) D = [] for _ in range(N): p = -pq_seen[0] q = -pq_unseen[0] + X if p > q: D.append(p) heappop(pq_seen) else: D.append(q) heappop(pq_unseen) cs = [0] * (N+1) for i in range(N): cs[i+1] = cs[i] + D[i] K = int(input()) C = list(map(int, input().split())) ans = 0 for c in C: ans += cs[c] print(ans) if __name__ == '__main__': main()