#include using namespace std; using ll = long long; using ull = unsigned long long; #define rep(i,n) for(int i=0; i<(int)(n); i++) #define MOD 1000000007 #define MOD2 998244353 #define INF 1000000007 #define LINF 1000000000000000007LL #define PI 3.14159265359 #define P pair template inline bool chmax(T &a, const T &b){ if(a inline bool chmin(T &a, const T &b){ if(a>b) {a=b; return true;} else return false; } struct Edge{ int to; ll cost; Edge(int to, ll cost) : to(to), cost(cost) {} }; typedef vector Edges; typedef vector Graph; void add_edge(Graph &g,int from,int to,ll cost,bool rev,ll rev_cost){ g[from].push_back(Edge(to,cost)); if(rev) g[to].push_back(Edge(from,rev_cost)); } void solve(){ int n,m,x; cin>>n>>m>>x; vector a(n),b(n); rep(i,n){ cin>>a[i]>>b[i]; b[i]--; } int k; cin>>k; vector c(k); rep(i,k) cin>>c[i]; //---------------------------------------- vector> kind(m); rep(i,n){ kind[b[i]].push_back(a[i]); } vector points; rep(i,m){ if(kind[i].size()){ sort(kind[i].begin(),kind[i].end(),greater()); kind[i][0]+=x; } for(auto p : kind[i]) points.push_back(p); } sort(points.begin(),points.end(),greater()); vector solved(n+1); solved[0]=k; rep(i,k) solved[c[i]+1]--; rep(i,n) solved[i+1]+=solved[i]; ll ans=0; rep(i,n) ans += solved[i+1]*points[i]; cout<