`#include[HTML_REMOVED]
using namespace std;
pragma GCC optimize(2,3,”Ofast”,”inline”)
define int long long
const int maxn=3e5+10;
int n,m,c,a[maxn];
struct node{
int l,r,w;
bool inqueue;
};
unordered_map[HTML_REMOVED] mp;
priority_queue[HTML_REMOVED],greater[HTML_REMOVED] > q;
inline int read()
{
int x=0,f=1;
char ch=getchar();
while(ch<‘0’||ch>‘9’)
{
if(ch==’-‘)
f=-1;
ch=getchar();
}
while(ch>=‘0’ && ch<=‘9’)
x=x10+ch-‘0’,ch=getchar();
return xf;
}
void write(int x)
{
if(x<0)
putchar(‘-‘),x=-x;
if(x>9)
write(x/10);
putchar(x%10+‘0’);
return;
}
signed main(){
c=read();m=read();n=read();
for(int i=1;i<=m;i){
int x,y;
x=read();y=read();
mp[x].w=y;
a[i]=x;
mp[x].inqueue=0;
}
sort(a+1,a+1+m);
for(int i=1;i<=m;i){
if(i!=1)mp[a[i]].l=a[i-1];
else mp[a[i]].l=0;
if(i!=m)mp[a[i]].r=a[i+1];
else mp[a[i]].r=0;
}
while(n–){
int x;
x=read();
mp[x].w;
if(mp[x].w>=5){
q.push(x);
}
while(!q.empty()){
int p=q.top();
q.pop();
mp[mp[p].l].r=mp[p].r;
mp[mp[p].r].l=mp[p].l;
if(mp[p].l!=0){
int u=mp[p].l;
mp[u].w;
if(mp[u].w>=5){
if(!mp[u].inqueue){
q.push(u);
mp[u].inqueue=1;
}
}
}
if(mp[p].r!=0){
int v=mp[p].r;
mp[v].w++;
if(mp[v].w>=5){
if(!mp[v].inqueue){
q.push(v);
mp[v].inqueue=1;
}
}
}
mp.erase(p);
m–;
}
write(m);
printf(“\n”);
}
}`