#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(0); ll N,M,X; cin >> N >> M >> X; vector> col(M); rep(i,N) { ll A,B; cin >> A >> B; B--; col[B].push_back(A); } vector D; rep(i,M) if(!col[i].empty()) { sort(col[i].begin(), col[i].end()); col[i].back() += X; for(ll x : col[i]) D.push_back(x); } sort(D.rbegin(), D.rend()); vector sumD(N + 1, 0); rep(i,N) sumD[i + 1] += sumD[i] + D[i]; ll ans = 0; int K; cin >> K; rep(i,K) { int c; cin >> c; ans += sumD[c]; } cout << ans << endl; }