#include<cstdio>
#include<map>
using namespace std;
typedef pair<int,int> Pair;

map<int,Pair> tree;
map<Pair,bool> checks;
int n, m;

void source() {
	Pair u, v;
	for(int i=0; i<m-1; i++) {
		for(int j=i+1; j<m; j++) {
			u = tree[i];
			v = tree[j];
			if(u.first == v.second && (!checks.count(make_pair(u.second,v.first)) || !checks.count(make_pair(u.first,v.second)))) {
				printf("NO\n");
				return;
			}
			else if(u.second == v.first && (!checks.count(make_pair(u.first,v.second)) || !checks.count(make_pair(u.second,v.first) ))) {
				printf("NO\n");
				return;
			}
			else if(u.first == v.first && (!checks.count(make_pair(u.second,v.second)) || !checks.count(make_pair(v.second,u.second)))) {
				printf("NO\n");
				return ;
			}
			else if(u.second == v.second && (!checks.count(make_pair(u.first,v.first)) || !checks.count(make_pair(v.first,u.first)))) {
				printf("NO\n");
				return;
			}
		}
	}
	printf("YES\n");
}

int main()
{
	while(scanf("%d%d", &n, &m) != EOF) {
		tree.clear();
		checks.clear();
		for(int i=0; i<m; i++) {
			int x, y;
			scanf("%d%d", &x, &y);
			tree[i] = make_pair(x,y);
			checks[tree[i]] = true;
		}
		source();
	}
	return 0;
}


#include<cstdio>
#include<iostream>
#define maxn 150123
typedef long long ll;

int f[maxn];
ll e[maxn], v[maxn];

int F(int x) {
	if(x==f[x]) return x;
	return f[x] = F(f[x]);
}

int main()
{
	int n, m;
	while(scanf("%d%d", &n, &m) != EOF) {
		for(int i=1; i<=n; i++) {
			f[i] = i;
			e[i] = 0;
			v[i] = 1;
		}
		for(int i=1; i<=m; i++) {
			int x, y;
			scanf("%d%d", &x, &y);
			if(F(x)==F(y)) e[f[x]]++;
			else {
				e[f[y]] += e[f[x]] + 1;
				v[f[y]] += v[f[x]];
				f[f[x]] = f[y];
			}
		}
		bool flag = true;
		for(int i=1; i<=n; i++) {
			if(f[i]==i) {
				printf("%d %d\n", e[i], v[i]);
				if(e[i] != v[i]*(v[i]-1)/2) {
					flag = false;
					break;
				}
			}
		}
		if(flag) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

int fa[150005];

int find(int x)
{
	int r=x;
	while(fa[r]!=r) r=fa[r];
	int i=x,j;
	while(i!=r)
	{
		j=fa[i];
		fa[i]=r;
		i=j;
	}
	return r;
}
void unin(int x,int y)
{
	x=find(x);
	y=find(y);
	if(x!=y) fa[x]=y;
	return;
}
int main()
{
	LL n,m,a,b;
	scanf("%I64d%I64d",&n,&m);
	for(int i=0;i<=n+1;i++) fa[i]=i;
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&a,&b);
		unin(a,b);
	}
	sort(fa+1,fa+n+1);
	LL sum=0,cnt=1;
	for(int i=1;i<=n+1;i++)
	{
		if(fa[i]!=fa[i-1]) sum+=(cnt-1)*cnt/2,cnt=1;
		else cnt++;
	}
	if(sum==m) printf("YES\n");
	else printf("NO\n");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

int fa[150005];

int find(int x)
{
	if(fa[x]!=x) fa[x]=find(fa[x]);
	return fa[x];
}
void unin(int x,int y)
{
	x=find(x);
	y=find(y);
	if(x!=y) fa[x]=y;
	return;
}
int main()
{
	LL n,m,a,b;
	scanf("%I64d%I64d",&n,&m);
	for(int i=0;i<=n+1;i++) fa[i]=i;
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&a,&b);
		unin(a,b);
		unin(b,a);
		fa[a]=find(a);
		fa[b]=find(b);
	}
	//for(int i=1;i<=n;i++) cout<<fa[i]<<" ";
	sort(fa+1,fa+n+1);
	//for(int i=1;i<=n;i++) cout<<fa[i]<<" ";
	LL sum=0,cnt=1;
	for(int i=2;i<=n+1;i++)
	{
		if(fa[i]!=fa[i-1]) sum+=(cnt-1)*cnt/2,cnt=1;
		else cnt++;
	}
	if(sum==m) printf("YES\n");
	else printf("NO\n");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

int fa[150005];

int find(int x)
{
	int r=x;
	while(fa[r]!=r) r=fa[r];
	int i=x,j;
	while(i!=r)
	{
		j=fa[i];
		fa[i]=r;
		i=j;
	}
	return r;
}
void unin(int x,int y)
{
	x=find(x);
	y=find(y);
	if(x!=y) fa[x]=y;
	return;
}
int main()
{
	LL n,m,a,b;
	scanf("%I64d%I64d",&n,&m);
	for(int i=0;i<=n+1;i++) fa[i]=i;
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&a,&b);
		unin(a,b);
	}
	sort(fa+1,fa+n+1);
	LL sum=0,cnt=1;
	for(int i=1;i<=n+1;i++)
	{
		if(fa[i]!=fa[i-1]) sum+=(cnt-1)*cnt/2,cnt=1;
		else cnt++;
	}
	if(sum==m) printf("YES\n");
	else printf("NO\n");
	 return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

int fa[150005];

int find(int x)
{
	if(fa[x]!=x) fa[x]=find(fa[x]);
	return fa[x];
}
void unin(int x,int y)
{
	x=find(x);
	y=find(y);
	if(x!=y) fa[x]=y;
	return;
}
int main()
{
	LL n,m;
	int a,b;
	scanf("%I64d%I64d",&n,&m);
	for(int i=0;i<=n+1;i++) fa[i]=i;
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&a,&b);
		if(find(a)!=find(b)) unin(a,b);
	}
	sort(fa+1,fa+n+1);
	long long sum=0,cnt=1;
	for(int i=2;i<=n+1;i++)
	{
		if(fa[i]!=fa[i-1]) sum+=(cnt-1)*cnt/2,cnt=1;
		else cnt++;
	}
	if(sum==m) printf("YES\n");
	else printf("NO\n");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

int fa[150005];

int find(int x)
{
	if(fa[x]!=x) fa[x]=find(fa[x]);
	return fa[x];
}
void unin(int x,int y)
{
	x=find(x);
	y=find(y);
	if(x!=y) fa[x]=y;
	return;
}
int main()
{
	LL n,m,a,b;
	scanf("%I64d%I64d",&n,&m);
	for(int i=0;i<=n+1;i++) fa[i]=i;
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&a,&b);
		unin(a,b);
	}
	for(int i=1;i<=n;i++) fa[i]=find(i);
	sort(fa+1,fa+n+1);
	LL sum=0,cnt=1;
	for(int i=2;i<=n+1;i++)
	{
		if(fa[i]!=fa[i-1]) sum+=(cnt-1)*cnt/2,cnt=1;
		else cnt++;
	}
	if(sum==m) printf("YES\n");
	else printf("NO\n");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

int fa[150005];

int find(int x)
{
	if(fa[x]!=x) fa[x]=find(fa[x]);
	return fa[x];
}
void unin(int x,int y)
{
	x=find(x);
	y=find(y);
	if(x!=y) fa[x]=y;
	return;
}
int main()
{
	LL n,m,a,b;
	scanf("%I64d%I64d",&n,&m);
	for(int i=0;i<=n+1;i++) fa[i]=i;
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&a,&b);
		unin(a,b);
		fa[a]=find(a);
		fa[b]=find(b);
	}
	sort(fa+1,fa+n+1);
	LL sum=0,cnt=1;
	for(int i=1;i<=n+1;i++)
	{
		if(fa[i]!=fa[i-1]) sum+=(cnt-1)*cnt/2,cnt=1;
		else cnt++;
	}
	if(sum==m) printf("YES\n");
	else printf("NO\n");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

int fa[150005];

int find(int x)
{
	int r=x;
	while(fa[r]!=r) r=fa[r];
	int i=x,j;
	while(i!=r)
	{
		j=fa[i];
		fa[i]=r;
		i=j;
	}
}
void unin(int x,int y)
{
	x=find(x);
	y=find(y);
	if(x!=y) fa[x]=y;
	return;
}
int main()
{
	int n,m,a,b;
	scanf("%I64d%I64d",&n,&m);
	for(int i=0;i<=n+1;i++) fa[i]=i;
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&a,&b);
		unin(a,b);
	}
	sort(fa+1,fa+n+1);
	LL sum=0,cnt=1;
	for(int i=1;i<=n+1;i++)
	{
		if(fa[i]!=fa[i-1]) sum+=(cnt-1)*cnt/2,cnt=1;
		else cnt++;
	}
	if(sum==m) printf("YES\n");
	else printf("NO\n");
	return 0;
}


#include<iostream>
#include<cstdio>
#include<vector>

using namespace std;
int n,m;
LL scc,e;
vector<int>v[450005];
int vis[450005];
void dfs(int x)
{
	scc++;
	vis[x]=1;
	for(int i=0;i<v[x].size();i++)
	{
		e++;
		if(vis[v[x][i]])continue;
		dfs(v[x][i]);
	}
}
int main()
{
	scanf("%d %d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int a,b;
		scanf("%d %d",&a,&b);
		v[a].push_back(b);
		v[b].push_back(a);
	}
	for(int i=1;i<=n;i++)
	{
		scc=0;e=0;
		if(vis[i])continue;
		dfs(i);
		if(scc*(scc-1)!=e)
		{
			printf("NO");
			return 0;
		}
	}
	printf("YES");
}


#include<iostream>
#include<cstdio>
#include<vector>

using namespace std;
int n,m;
long long scc,e;
vector<int>v[450005];
int vis[450005];
void dfs(int x)
{
	scc++;
	vis[x]=1;
	for(int i=0;i<v[x].size();i++)
	{
		e++;
		if(vis[v[x][i]])continue;
		dfs(v[x][i]);
	}
}
int main()
{
	scanf("%d %d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int a,b;
		scanf("%d %d",&a,&b);
		v[a].push_back(b);
		v[b].push_back(a);
	}
	for(int i=1;i<=n;i++)
	{
		scc=0;e=0;
		if(vis[i])continue;
		dfs(i);
		if(scc*(scc-1)!=e)
		{
			printf("NO");
			return 0;
		}
	}
	printf("YES");
}


#include<iostream>
#include<cstdio>
#include<vector>

using namespace std;
int n,m;
int scc,e;
vector<int>v[450005];
int vis[450005];
void dfs(int x)
{
	scc++;
	vis[x]=1;
	for(int i=0;i<v[x].size();i++)
	{
		e++;
		if(vis[v[x][i]])continue;
		dfs(v[x][i]);
	}
}
int main()
{
	scanf("%d %d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int a,b;
		scanf("%d %d",&a,&b);
		v[a].push_back(b);
		v[b].push_back(a);
	}
	for(int i=1;i<=n;i++)
	{
		scc=0;e=0;
		if(vis[i])continue;
		dfs(i);
		if(scc*(scc-1)!=e)
		{
			printf("NO");
			return 0;
		}
	}
	printf("YES");
}


#include<iostream>
#include<vector>

using namespace std;
int n,m;
int scc,e;
vector<int>v[150005];
int vis[150005];
void dfs(int x)
{
	scc++;
	vis[i]=1;
	for(int i=0;i<v[x].size();i++)
	{
		e++;
		if(vis[v[x][i]])continue;
		dfs(v[x][i]);
	}
}
int main()
{
	scanf("%d %d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int a,b;
		scanf("%d %d",&a,&b);
		v[a].push_back(b);
		v[b].push_back(a);
	}
	for(int i=1;i<=n;i++)
	{
		scc=0;e=0;
		if(vis[i])continue;
		dfs(i);
		if(scc*(scc-1)!=e)
		{
			printf("NO");
			return 0;
		}
	}
	printf("YES");
}


#include<iostream>
#include<cstdio>
#include<vector>

using namespace std;
int n,m;
int scc,e;
vector<int>v[150005];
int vis[150005];
void dfs(int x)
{
	scc++;
	vis[x]=1;
	for(int i=0;i<v[x].size();i++)
	{
		e++;
		if(vis[v[x][i]])continue;
		dfs(v[x][i]);
	}
}
int main()
{
	scanf("%d %d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int a,b;
		scanf("%d %d",&a,&b);
		v[a].push_back(b);
		v[b].push_back(a);
	}
	for(int i=1;i<=n;i++)
	{
		scc=0;e=0;
		if(vis[i])continue;
		dfs(i);
		if(scc*(scc-1)!=e)
		{
			printf("NO");
			return 0;
		}
	}
	printf("YES");
}


#include<bits/stdc++.h>
using namespace std;
#define me boss
#define ll long long int
vector<int>graph[1500001];
set<int>s;
void dfs2(int start);
int vis[1500010],parent[1500001],f=1,v=0,e=0;
void dfs(int start)
{
    v++;
    vis[start]=1;
    for(int i=0;i<graph[start].size();i++)
    {
        e++;
        if(vis[graph[start][i]]==0)
        {
            dfs(graph[start][i]);
        }

    }
}
int main()
{
    int n,m,a1,b1;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        cin>>a1>>b1;
        graph[a1].push_back(b1);
        graph[b1].push_back(a1);
        s.insert(a1);
        s.insert(b1);
    }
    for(__typeof(s.begin())it=s.begin();it!=s.end();it++)
    {
        //if(vis[*it]==0)
        if(vis[*it]==0)
            {dfs(*it);
            //cout<<v<<" "<<e<<endl;
            e=e/2;
            if(e==(v*(v-1))/2)
                f=1;
            else
            {
                f=0;
                break;
            }
            }
            v=0,e=0;
    }
    if(f==1)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define me boss
#define ll long long int
vector<int>graph[150001];
set<int>s;
void dfs2(int start);
int vis[150010],parent[150001],f=1,v=0,e=0;
void dfs(int start)
{
    v++;
    vis[start]=1;
    for(int i=0;i<graph[start].size();i++)
    {
        e++;
        if(vis[graph[start][i]]==0)
        {
            dfs(graph[start][i]);
        }

    }
}
int main()
{
    int n,m,a1,b1;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        cin>>a1>>b1;
        graph[a1].push_back(b1);
        graph[b1].push_back(a1);
        s.insert(a1);
        s.insert(b1);
    }
    memset(vis,0,sizeof(vis));
    for(__typeof(s.begin())it=s.begin();it!=s.end();it++)
    {
        if(vis[*it]==0){
            e=e/2;
            if(v==2){
                f=1;
            }
            else if(e*2==(v*(v-1))){
                f=1;
            }
            else{
                f=0;
                break;
            }
        }
        v=0,e=0;
    }
    if(f==1)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define me boss
#define ll long long int
vector<int>graph[100001];
set<int>s;
void dfs2(int start);
int vis[100010],parent[100001],f=0,v=0,e=0;
void dfs(int start)
{
    v++;
    vis[start]=1;
    for(int i=0;i<graph[start].size();i++)
    {
        e++;
        if(vis[graph[start][i]]==0)
        {
            dfs(graph[start][i]);
        }

    }
}
int main()
{
    int n,m,a1,b1;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        cin>>a1>>b1;
        graph[a1].push_back(b1);
        graph[b1].push_back(a1);
        s.insert(a1);
        s.insert(b1);
    }
    for(__typeof(s.begin())it=s.begin();it!=s.end();it++)
    {
        //if(vis[*it]==0)
        if(vis[*it]==0)
            {dfs(*it);
            //cout<<v<<" "<<e<<endl;
            e=e/2;
            if(e==(v*(v-1))/2)
                f=1;
            else
            {
                f=0;
                break;
            }
            }
            v=0,e=0;
    }
    if(f==1)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define me boss
#define ll long long int
vector<int>graph[1500001];
set<int>s;
void dfs2(int start);
int vis[1500010],parent[1500001],f=1;
long long int v=0,e=0;
void dfs(int start)
{
    v++;
    vis[start]=1;
    for(int i=0;i<graph[start].size();i++)
    {
        e++;
        if(vis[graph[start][i]]==0)
        {
            dfs(graph[start][i]);
        }

    }
}
int main()
{
    int n,m,a1,b1;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        cin>>a1>>b1;
        graph[a1].push_back(b1);
        graph[b1].push_back(a1);
        s.insert(a1);
        s.insert(b1);
    }
    for(__typeof(s.begin())it=s.begin();it!=s.end();it++)
    {
        //if(vis[*it]==0)
        if(vis[*it]==0)
            {dfs(*it);
            //cout<<v<<" "<<e<<endl;
            if(e==(v*(v-1)))
                f=1;
            else
            {
                f=0;
                break;
            }
            }
            v=0,e=0;
    }
    if(f==1)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define me boss
#define ll long long int
vector<int>graph[1500001];
set<int>s;
void dfs2(int start);
int vis[1500010],parent[1500001],f=1, v=0,e=0;
void dfs(int start)
{
    v++;
    vis[start]=1;
    for(int i=0;i<graph[start].size();i++)
    {
        e++;
        if(vis[graph[start][i]]==0)
        {
            dfs(graph[start][i]);
        }

    }
}
int main()
{
    int n,m,a1,b1;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        cin>>a1>>b1;
        graph[a1].push_back(b1);
        graph[b1].push_back(a1);
        s.insert(a1);
        s.insert(b1);
    }
    for(__typeof(s.begin())it=s.begin();it!=s.end();it++)
    {
        //if(vis[*it]==0)
        if(vis[*it]==0)
            {dfs(*it);
            //cout<<v<<" "<<e<<endl;
            if(e==(v*(v-1)))
                f=1;
            else
            {
                f=0;
                break;
            }
            }
            v=0,e=0;
    }
    if(f==1)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;

return 0;
}


#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
#include<cstdio>
using namespace std;
const int maxn = 150005;
int vis[maxn] = { 0 };
vector<int> g[maxn];

void dfs(int a ,int&  vertices, int& tot)
{
	if (vis[a])	return;
	vis[a] = 1;
	tot += g[a].size();
	vertices++;
	for (int b : g[a])
		if (!vis[b])
			dfs(b, vertices, tot);
}

int main()
{
	int n, m;
	cin >> n >> m;
	while (m--)
	{
		int u, v; cin >> u>>v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	for (int i = 1; i <= n; i++)
	{
		if (vis[i])	continue;
		int tot = 0, vertices = 0;
		dfs(i, vertices, tot);
		if (tot != (long long)vertices * (vertices - 1))
			cout << "NO\n";
	}
	cout << "YES\n";
	return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn = 150005;
int n, m;
vector<int> g[maxn];
int vis[maxn];

bool judge(int u, int v)
{
	if (u == v)	return true;
	for (int i = 0; i < g[u].size(); i++)
	{
		int j = g[u][i];
		if (vis[j])	 continue;
		vis[j] = 1;
		if(judge(j , v))
			return true;
	}
	return false;
}

int main()
{
	while (cin >> n >> m)
	{
		for (int i = 0; i <= n; i++) vis[i] = 0 , g[i].clear();
		int i = 0;
		while (m--)
		{
			int u, v;
			cin >> u >> v;
			g[u].push_back(v);
			g[v].push_back(u);
		}
		bool ok = true;
		for (int i = 1; i <= n; i++)
		{
			for (int j = 1; j <= n; j++)	if (i != j)
			{
				for (int i = 0; i <= n; i++)	vis[i] = 0;
				vis[i] = 1;
				if (judge(i, j))
				{
					ok = false;
					for (int k = 0; k < g[i].size(); k++)
						if (g[i][k] == j)
							ok = true;
					if (!ok)		break;
				}
			}
			if (!ok)	break;
		}
		if (ok)
			cout << "YES";
		else
			cout << "NO";
		cout << endl;
	}
	return 0;
}


#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
#include<cstdio>
using namespace std;
const int maxn = 150005;
int vis[maxn] = { 0 };
vector<int> g[maxn];

void dfs(int a ,int& vertices, int& tot)
{
	if (vis[a])	return;
	vis[a] = 1;
	tot += g[a].size();
	vertices++;
	for (int i = 0; i < g[a].size(); i++)
	{
		int b = g[a][i];
		if (!vis[b])
			dfs(b, vertices, tot);
	}
}

int main()
{
	int n, m;
	cin >> n >> m;
	while (m--)
	{
		int u, v; cin >> u>>v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	for (int i = 1; i <= n; i++)
	{
		if (vis[i])	continue;
		int tot = 0, vertices = 0;
		dfs(i, vertices, tot);
		if (tot != (long long)vertices * (vertices - 1))
		{
			cout << "NO\n";
			return 0;
		}
	}
	cout << "YES\n";
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <climits>
#include <numeric>
#include<stdio.h>
#include <queue>
#include <iomanip>
#include <float.h>
#include <set>
#include<functional>
#include <stack>
#include <time.h>
#include <climits>
#include <bitset>
#include <fstream>
#include<map>
#include <cassert>
using namespace std;
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
vector<long long> divisor(long long n) {
	vector< long long> ret;
	for (long long i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(begin(ret), end(ret));
	return (ret);
}
struct LazySegmentTree {
private:
	int n;
	vector<int> node, lazy;
	vector<bool> lazyFlag;

public:
	LazySegmentTree(vector<int> v) {
		int sz = (int)v.size();
		n = 1; while (n < sz) n *= 2;
		node.resize(2 * n - 1);
		lazy.resize(2 * n - 1, INT_MAX);
		lazyFlag.resize(2 * n - 1, false);

		for (int i = 0; i<sz; i++) node[i + n - 1] = v[i];
		for (int i = n - 2; i >= 0; i--) node[i] = min(node[i * 2 + 1], node[i * 2 + 2]);
	}

	void lazyEvaluate(int k, int l, int r) {
		if (lazyFlag[k]) {
			node[k] = lazy[k];
			if (r - l > 1) {
				lazy[k * 2 + 1] = lazy[k * 2 + 2] = lazy[k];
				lazyFlag[k * 2 + 1] = lazyFlag[k * 2 + 2] = true;
			}
			lazyFlag[k] = false;
		}
	}

	void update(int a, int b, int x, int k = 0, int l = 0, int r = -1) {
		if (r < 0) r = n;
		lazyEvaluate(k, l, r);
		if (b <= l || r <= a) return;
		if (a <= l && r <= b) {
			lazy[k] = x;
			lazyFlag[k] = true;
			lazyEvaluate(k, l, r);
		}
		else {
			update(a, b, x, 2 * k + 1, l, (l + r) / 2);
			update(a, b, x, 2 * k + 2, (l + r) / 2, r);
			node[k] = min(node[2 * k + 1], node[2 * k + 2]);
		}
	}

	int find(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0) r = n;
		lazyEvaluate(k, l, r);
		if (b <= l || r <= a) return INT_MAX;
		if (a <= l && r <= b) return node[k];
		int vl = find(a, b, 2 * k + 1, l, (l + r) / 2);
		int vr = find(a, b, 2 * k + 2, (l + r) / 2, r);
		return min(vl, vr);
	}
};
#define ll long long
class UnionFind {
public:
	vector <ll> par; // 各元の親を表す配列
	vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

					 // Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;
		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}

	bool issame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}
};
struct segtree {
	int N, dat[4 * 200004];
	segtree() {}
	segtree(int n) {
		N = 1;
		while (N < n) N *= 2;
		for (int i = 0; i < 2 * N - 1; i++)
			dat[i] = INT_MAX;
	}
	// update k th element
	void update(int k, int a) {
		k += N - 1; // leaf
		dat[k] = a;
		while (k > 0) {
			k = (k - 1) / 2;
			dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
		}
	}
	// min [a, b)
	int query(int a, int b) { return query(a, b, 0, 0, N); }
	int query(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l) return INT_MAX;
		if (a <= l && r <= b) return dat[k];
		int m = (l + r) / 2;
		return min(query(a, b, k * 2 + 1, l, m), query(a, b, k * 2 + 2, m, r));
	}
};
struct segtree2 {
	int N, dat[4 * 200004];
	segtree2() {}
	segtree2(int n) {
		N = 1;
		while (N < n) N *= 2;
		for (int i = 0; i < 2 * N - 1; i++)
			dat[i] = INT_MIN;
	}
	// update k th element
	void update(int k, int a) {
		k += N - 1; // leaf
		dat[k] = a;
		while (k > 0) {
			k = (k - 1) / 2;
			dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]);
		}
	}
	// min [a, b)
	int query(int a, int b) { return query(a, b, 0, 0, N); }
	int query(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l) return INT_MIN;
		if (a <= l && r <= b) return dat[k];
		int m = (l + r) / 2;
		return max(query(a, b, k * 2 + 1, l, m), query(a, b, k * 2 + 2, m, r));
	}
};
typedef pair<int,int>p;
long long mod = 1e9+7;
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int n, m;
vector<int>graph[100004];
p highlow[100004];
vector<int>vec[100004];
signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> m;
	int a, b;
	for (int i = 0; i < m; i++) {
		cin >> a >> b;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	long long ans = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < graph[i].size(); j++) {
			int to = graph[i][j];
			if (to > i) { highlow[i].first += 1; vec[i].push_back(to); }
			else highlow[i].second += 1;
		}
		ans += (long long)highlow[i].first*highlow[i].second;
	}
	cout << ans<<"\n";
	int q;
	cin >> q;
	int v;
	while (q--) {
		cin >> v;
		ans -= highlow[v].first*highlow[v].second;
		highlow[v].second= highlow[v].first + highlow[v].second;
		highlow[v].first = 0;
		for (int i=0;i<vec[v].size();i++) {
			int to = vec[v][i];
			ans += highlow[to].second-highlow[to].first-1;
			highlow[to].first += 1;
			highlow[to].second -= 1;
			vec[to].push_back(v);
		}
		vec[v].clear();
		cout << ans<<"\n";
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <climits>
#include <numeric>
#include<stdio.h>
#include <queue>
#include <iomanip>
#include <float.h>
#include <set>
#include<functional>
#include <stack>
#include <time.h>
#include <climits>
#include <bitset>
#include <fstream>
#include<map>
#include <cassert>
using namespace std;
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
vector<long long> divisor(long long n) {
	vector< long long> ret;
	for (long long i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(begin(ret), end(ret));
	return (ret);
}
struct LazySegmentTree {
private:
	int n;
	vector<int> node, lazy;
	vector<bool> lazyFlag;

public:
	LazySegmentTree(vector<int> v) {
		int sz = (int)v.size();
		n = 1; while (n < sz) n *= 2;
		node.resize(2 * n - 1);
		lazy.resize(2 * n - 1, INT_MAX);
		lazyFlag.resize(2 * n - 1, false);

		for (int i = 0; i<sz; i++) node[i + n - 1] = v[i];
		for (int i = n - 2; i >= 0; i--) node[i] = min(node[i * 2 + 1], node[i * 2 + 2]);
	}

	void lazyEvaluate(int k, int l, int r) {
		if (lazyFlag[k]) {
			node[k] = lazy[k];
			if (r - l > 1) {
				lazy[k * 2 + 1] = lazy[k * 2 + 2] = lazy[k];
				lazyFlag[k * 2 + 1] = lazyFlag[k * 2 + 2] = true;
			}
			lazyFlag[k] = false;
		}
	}

	void update(int a, int b, int x, int k = 0, int l = 0, int r = -1) {
		if (r < 0) r = n;
		lazyEvaluate(k, l, r);
		if (b <= l || r <= a) return;
		if (a <= l && r <= b) {
			lazy[k] = x;
			lazyFlag[k] = true;
			lazyEvaluate(k, l, r);
		}
		else {
			update(a, b, x, 2 * k + 1, l, (l + r) / 2);
			update(a, b, x, 2 * k + 2, (l + r) / 2, r);
			node[k] = min(node[2 * k + 1], node[2 * k + 2]);
		}
	}

	int find(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0) r = n;
		lazyEvaluate(k, l, r);
		if (b <= l || r <= a) return INT_MAX;
		if (a <= l && r <= b) return node[k];
		int vl = find(a, b, 2 * k + 1, l, (l + r) / 2);
		int vr = find(a, b, 2 * k + 2, (l + r) / 2, r);
		return min(vl, vr);
	}
};
#define ll long long
class UnionFind {
public:
	vector <ll> par; // 各元の親を表す配列
	vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

					 // Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;
		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}

	bool issame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}
};
struct segtree {
	int N, dat[4 * 200004];
	segtree() {}
	segtree(int n) {
		N = 1;
		while (N < n) N *= 2;
		for (int i = 0; i < 2 * N - 1; i++)
			dat[i] = INT_MAX;
	}
	// update k th element
	void update(int k, int a) {
		k += N - 1; // leaf
		dat[k] = a;
		while (k > 0) {
			k = (k - 1) / 2;
			dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
		}
	}
	// min [a, b)
	int query(int a, int b) { return query(a, b, 0, 0, N); }
	int query(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l) return INT_MAX;
		if (a <= l && r <= b) return dat[k];
		int m = (l + r) / 2;
		return min(query(a, b, k * 2 + 1, l, m), query(a, b, k * 2 + 2, m, r));
	}
};
struct segtree2 {
	int N, dat[4 * 200004];
	segtree2() {}
	segtree2(int n) {
		N = 1;
		while (N < n) N *= 2;
		for (int i = 0; i < 2 * N - 1; i++)
			dat[i] = INT_MIN;
	}
	// update k th element
	void update(int k, int a) {
		k += N - 1; // leaf
		dat[k] = a;
		while (k > 0) {
			k = (k - 1) / 2;
			dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]);
		}
	}
	// min [a, b)
	int query(int a, int b) { return query(a, b, 0, 0, N); }
	int query(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l) return INT_MIN;
		if (a <= l && r <= b) return dat[k];
		int m = (l + r) / 2;
		return max(query(a, b, k * 2 + 1, l, m), query(a, b, k * 2 + 2, m, r));
	}
};
typedef pair<long long,long long>p;
long long mod = 1e9+7;
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int n, m;
vector<int>graph[100004];
p highlow[100004];
set<int>se[100004];
signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> m;
	int a, b;
	for (int i = 0; i < m; i++) {
		cin >> a >> b;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	long long ans = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < graph[i].size(); j++) {
			int to = graph[i][j];
			if (to > i) { highlow[i].first += 1; se[i].insert(to); }
			else highlow[i].second += 1;
		}
		ans += highlow[i].first*highlow[i].second;
	}
	cout << ans<<"\n";
	int q;
	cin >> q;
	int v;
	while (q--) {
		cin >> v;
		ans -= highlow[v].first*highlow[v].second;
		highlow[v].second= highlow[v].first + highlow[v].second;
		highlow[v].first = 0;
		for (auto itr = se[v].begin(); itr != se[v].end(); itr++) {
			int to = *itr;
			ans -= highlow[to].first*highlow[to].second;
			highlow[to].first += 1;
			highlow[to].second -= 1;
			ans+= highlow[to].first*highlow[to].second;
			se[to].insert(v);
		}
		se[v].clear();
		cout << ans<<"\n";
	}
}


#include <bits/stdc++.h>
#define ll long long
#define db long double
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

using namespace std;

const int N = 2e5 + 7;
const int SQ = sqrt(N);

vector <vector <pair <int, int> > > ing, outg;

int main(){
#ifdef LOCAL
	freopen("C_input.txt", "r", stdin);
	//freopen("C_output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m;
	cin >> n >> m;

	ing.resize(n);
	outg.resize(n);

	for (int i = 0; i < m; i++) {
		int v, u;
		cin >> v >> u;
		v--, u--;
		if (v < u) swap(v, u);
		outg[v].push_back({u, ing[u].size()});
		ing[u].push_back({v, outg[v].size() - 1});
	}
	ll res = 0;
	for (int v = 0; v < n; v++) {
		res += ing[v].size() * (ll) outg[v].size();
	}
	cout << res << "\n";

	int q;
	cin >> q;

	for (int i = 0; i < q; i++) {
		int v;
		cin >> v;
		v--;
		res -= ing[v].size() * (ll) outg[v].size();
		for (int i = 0; i < (int) ing[v].size(); i++) {
			auto e = ing[v][i];
			int u = e.first, id = e.second;
			res -= ing[u].size() * (ll) outg[u].size();
			//assert(outg[u].size());
			auto e1 = outg[u].back();
			if (id != (int) outg[u].size() - 1) {
				swap(outg[u].back(), outg[u][id]);
				ing[e1.first][e1.second].second = id;
			}
			outg[u].pop_back();
			outg[v].push_back({u, ing[u].size()});
			ing[u].push_back({v, outg[v].size() - 1});
			res += ing[u].size() * (ll) outg[u].size();
		}
		ing[v].clear();
		cout << res << "\n";
	}

}


#include <bits/stdc++.h>
#define ll long long
#define db long double
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

using namespace std;

const int N = 2e5 + 7;
const int SQ = sqrt(N);

vector <vector <pair <int, int> > > ing, outg;

int main(){
#ifdef LOCAL
	freopen("C_input.txt", "r", stdin);
	//freopen("C_output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m;
	cin >> n >> m;

	ing.resize(n);
	outg.resize(n);

	for (int i = 0; i < m; i++) {
		int v, u;
		cin >> v >> u;
		v--, u--;
		if (v < u) swap(v, u);
		outg[v].push_back({u, ing[u].size()});
		ing[u].push_back({v, outg[v].size() - 1});
	}
	ll res = 0;
	for (int v = 0; v < n; v++) {
		res += ing[v].size() * (ll) outg[v].size();
	}
	cout << res << "\n";

	int q;
	cin >> q;

	for (int i = 0; i < q; i++) {
		int v;
		cin >> v;
		v--;
		res -= ing[v].size() * (ll) outg[v].size();
		for (int i = 0; i < (int) ing[v].size(); i++) {
			auto e = ing[v][i];
			int u = e.first, id = e.second;
			res -= ing[u].size() * (ll) outg[u].size();
			auto e1 = outg[u].back();
			if (e1.first != v) {
				swap(e1, outg[u][id]);
				ing[e1.first][e.second].second = id;
			}
			outg[u].pop_back();
			outg[v].push_back({u, ing[u].size()});
			ing[u].push_back({v, outg[v].size() - 1});
			res += ing[u].size() * (ll) outg[u].size();
		}
		ing[v].clear();
		cout << res << "\n";
	}

}


#include <bits/stdc++.h>
#define ll long long
#define db long double
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

using namespace std;

const int N = 2e5 + 7;
const int SQ = sqrt(N);

vector <vector <pair <int, int> > > ing, outg;

int main(){
#ifdef LOCAL
	freopen("C_input.txt", "r", stdin);
	//freopen("C_output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m;
	cin >> n >> m;

	ing.resize(n);
	outg.resize(n);

	for (int i = 0; i < m; i++) {
		int v, u;
		cin >> v >> u;
		v--, u--;
		if (v < u) swap(v, u);
		outg[v].push_back({u, ing[u].size()});
		ing[u].push_back({v, outg[v].size() - 1});
	}
	ll res = 0;
	for (int v = 0; v < n; v++) {
		res += ing[v].size() * (ll) outg[v].size();
	}
	cout << res << "\n";

	int q;
	cin >> q;

	for (int i = 0; i < q; i++) {
		int v;
		cin >> v;
		v--;
		res -= ing[v].size() * (ll) outg[v].size();
		for (int i = 0; i < (int) ing[v].size(); i++) {
			auto e = ing[v][i];
			int u = e.first, id = e.second;
			res -= ing[u].size() * (ll) outg[u].size();
			auto &e1 = outg[u].back();
			if (e1.first != v) {
				swap(e1, outg[u][id]);
				ing[e1.first][e1.second].second = id;
			}
			outg[u].pop_back();
			outg[v].push_back({u, ing[u].size()});
			ing[u].push_back({v, outg[v].size() - 1});
			res += ing[u].size() * (ll) outg[u].size();
		}
		ing[v].clear();
		cout << res << "\n";
	}

}


#include <bits/stdc++.h>
#define ll long long
#define db long double
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

using namespace std;

const int N = 2e5 + 7;
const int SQ = sqrt(N);

vector <vector <pair <int, int> > > ing, outg;

int main(){
#ifdef LOCAL
	freopen("C_input.txt", "r", stdin);
	//freopen("C_output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m;
	cin >> n >> m;

	ing.resize(n);
	outg.resize(n);

	for (int i = 0; i < m; i++) {
		int v, u;
		cin >> v >> u;
		v--, u--;
		if (v < u) swap(v, u);
		outg[v].push_back({u, ing[u].size()});
		ing[u].push_back({v, outg[v].size() - 1});
	}
	ll res = 0;
	for (int v = 0; v < n; v++) {
		res += ing[v].size() * (ll) outg[v].size();
	}
	cout << res << "\n";

	int q;
	cin >> q;

	for (int i = 0; i < q; i++) {
		int v;
		cin >> v;
		v--;
		res -= ing[v].size() * (ll) outg[v].size();
		for (int i = 0; i < (int) ing[v].size(); i++) {
			auto e = ing[v][i];
			int u = e.first, id = e.second;
			res -= ing[u].size() * (ll) outg[u].size();
			auto e1 = outg[u].back();
			if (e1.first != v) {
				swap(e1, outg[u][id]);
				ing[e1.first][e1.second].second = id;
			}
			outg[u].pop_back();
			outg[v].push_back({u, ing[u].size()});
			ing[u].push_back({v, outg[v].size() - 1});
			res += ing[u].size() * (ll) outg[u].size();
		}
		ing[v].clear();
		cout << res << "\n";
	}

}


#include <bits/stdc++.h>
#define ll long long
#define db long double
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

using namespace std;

const int N = 2e5 + 7;
const int SQ = sqrt(N);

vector <vector <pair <int, int> > > ing, outg;

int main(){
#ifdef LOCAL
	freopen("C_input.txt", "r", stdin);
	//freopen("C_output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m;
	cin >> n >> m;

	ing.resize(n);
	outg.resize(n);

	for (int i = 0; i < m; i++) {
		int v, u;
		cin >> v >> u;
		v--, u--;
		if (v < u) swap(v, u);
		outg[v].push_back({u, ing[u].size()});
		ing[u].push_back({v, outg[v].size() - 1});
	}
	ll res = 0;
	for (int v = 0; v < n; v++) {
		res += ing[v].size() * (ll) outg[v].size();
	}
	cout << res << "\n";

	int q;
	cin >> q;

	for (int i = 0; i < q; i++) {
		int v;
		cin >> v;
		v--;
		res -= ing[v].size() * (ll) outg[v].size();
		for (int i = 0; i < (int) ing[v].size(); i++) {
			auto e = ing[v][i];
			int u = e.first, id = e.second;
			res -= ing[u].size() * (ll) outg[u].size();
			assert(outg[u].size());
			auto e1 = outg[u].back();
			if (id != (int) outg[u].size() - 1) {
				swap(outg[u].back(), outg[u][id]);
				ing[e1.first][e1.second].second = id;
			}
			outg[u].pop_back();
			outg[v].push_back({u, ing[u].size()});
			ing[u].push_back({v, outg[v].size() - 1});
			res += ing[u].size() * (ll) outg[u].size();
		}
		ing[v].clear();
		cout << res << "\n";
	}

}


#include <bits/stdc++.h>
#define ll long long
#define db long double
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

using namespace std;

const int N = 2e5 + 7;
const int SQ = sqrt(N);

vector <vector <pair <int, int> > > ing, outg;

int main(){
#ifdef LOCAL
	freopen("C_input.txt", "r", stdin);
	//freopen("C_output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m;
	cin >> n >> m;

	ing.resize(n);
	outg.resize(n);

	for (int i = 0; i < m; i++) {
		int v, u;
		cin >> v >> u;
		v--, u--;
		if (v < u) swap(v, u);
		outg[v].push_back({u, ing[u].size()});
		ing[u].push_back({v, outg[v].size() - 1});
	}
	ll res = 0;
	for (int v = 0; v < n; v++) {
		res += ing[v].size() * (ll) outg[v].size();
	}
	cout << res << "\n";

	int q;
	cin >> q;

	for (int i = 0; i < q; i++) {
		int v;
		cin >> v;
		v--;
		res -= ing[v].size() * (ll) outg[v].size();
		for (int i = 0; i < (int) ing[v].size(); i++) {
			auto e = ing[v][i];
			int u = e.first, id = e.second;
			res -= ing[u].size() * (ll) outg[u].size();
			auto &e1 = outg[u].back();
			if (id != (int) outg[u].size() - 1) {
				swap(outg[u].back(), outg[u][id]);
				ing[e1.first][e1.second].second = id;
			}
			outg[u].pop_back();
			outg[v].push_back({u, ing[u].size()});
			ing[u].push_back({v, outg[v].size() - 1});
			res += ing[u].size() * (ll) outg[u].size();
		}
		ing[v].clear();
		cout << res << "\n";
	}

}


// Bismillahir Rahmanir Rahim
#include <bits/stdc++.h>

using namespace std;

#define double int double
#define Long long long
#define EPS 1e-12
#define PI acos(-1.0)

#define MAX 10000000
#define MOD 1000000007

#define POS_INF (1LL << 60)
#define NEG_INF (-(1LL << 60))

#define RIGHT_MOST_INDEX (1 << 30)
#define LEFT_MOST_INDEX (-(1 << 30))

#define MEMSET(x,y) memset(x, y, sizeof(x))
#define PB push_back
#define MP make_pair
#define SORT(A) sort(A.begin(), A.end());
#define REVERSE(A) reverse(A.begin(), A.end());

vector<Long>adj[MAX+9];
Long IN[MAX+9], OUT[MAX+9];
Long ANS;

void ADD_SINGLE(Long from, Long to)
{
    ANS -= IN[from] * OUT[from];
    ANS -= IN[to] * OUT[to];

    IN[to]++;
    OUT[from]++;

    ANS += IN[from] * OUT[from];
    ANS += IN[to] * OUT[to];
}

void DELETE_SINGLE(Long from, Long to)
{
    ANS -= IN[from] * OUT[from];
    ANS -= IN[to] * OUT[to];

    IN[to]--;
    OUT[from]--;

    ANS += IN[from] * OUT[from];
    ANS += IN[to] * OUT[to];
}

int main()
{
    Long i,j,k,l,n,m=0,tot,temp,curr,val,prev,a,b,c,t,ans,flag,x,y,siz,w,h,d,ii,jj,xx,yy,ind,len,max_n,q,s,f,g;

    scanf("%lld%lld", &n, &m);
    for(i=1; i<=m; i++)
    {
        scanf("%lld%lld", &j, &k);
        if(j > k) swap(j, k);

        ADD_SINGLE(k, j);
        adj[j].PB(k);
    }

    printf("%lld\n", ANS);

    cin>>q;
    while(q--)
    {
        scanf("%lld", &j);
        for(i=0; i<adj[j].size(); i++)
        {
            DELETE_SINGLE(adj[j][i], j);

            ADD_SINGLE(j, adj[j][i]);
            adj[adj[j][i]].PB(j);
        }

        adj[j].clear();
        printf("%lld\n", ANS);
    }
}


// Bismillahir Rahmanir Rahim
#include <bits/stdc++.h>

using namespace std;

#define double int double
#define Long long long
#define EPS 1e-12
#define PI acos(-1.0)

#define MAX 100000
#define MOD 1000000007

#define POS_INF (1LL << 60)
#define NEG_INF (-(1LL << 60))

#define RIGHT_MOST_INDEX (1 << 30)
#define LEFT_MOST_INDEX (-(1 << 30))

#define MEMSET(x,y) memset(x, y, sizeof(x))
#define PB push_back
#define MP make_pair
#define SORT(A) sort(A.begin(), A.end());
#define REVERSE(A) reverse(A.begin(), A.end());

vector<Long>adj[MAX+9];
Long IN[MAX+9], OUT[MAX+9];
Long ANS;

void ADD_SINGLE(Long from, Long to)
{
    ANS -= IN[from] * OUT[from];
    ANS -= IN[to] * OUT[to];

    IN[to]++;
    OUT[from]++;

    ANS += IN[from] * OUT[from];
    ANS += IN[to] * OUT[to];
}

void DELETE_SINGLE(Long from, Long to)
{
    ANS -= IN[from] * OUT[from];
    ANS -= IN[to] * OUT[to];

    IN[to]--;
    OUT[from]--;

    ANS += IN[from] * OUT[from];
    ANS += IN[to] * OUT[to];
}

int main()
{
    Long i,j,k,l,n,m=0,tot,temp,curr,val,prev,a,b,c,t,ans,flag,x,y,siz,w,h,d,ii,jj,xx,yy,ind,len,max_n,q,s,f,g;

    scanf("%lld%lld", &n, &m);
    for(i=1; i<=m; i++)
    {
        scanf("%lld%lld", &j, &k);
        if(j > k) swap(j, k);

        ADD_SINGLE(k, j);
        adj[j].PB(k);
    }

    printf("%lld\n", ANS);

    cin>>q;
    while(q--)
    {
        scanf("%lld", &j);
        for(i=0; i<adj[j].size(); i++)
        {
            DELETE_SINGLE(adj[j][i], j);

            ADD_SINGLE(j, adj[j][i]);
            adj[adj[j][i]].PB(j);
        }

        adj[j].clear();
        printf("%lld\n", ANS);
    }
}


#include<cstdio>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
int n, m, U[101000], Deg[101000], w[301000], Last[101000], Q;
long long sum;
vector<int>E[101000];
map<int, int>Map[101000];
void Add(int a, int b) {
	sum -= (long long)U[a] * (Deg[a] - U[a]);
	U[a] += b;
	sum += (long long)U[a] * (Deg[a] - U[a]);
}
int main() {
	//freopen("input.txt", "r", stdin);
	int i, a, b, j;
	scanf("%d%d", &n, &m);
	for (i = 0; i < m; i++) {
		scanf("%d%d", &a, &b);
		Map[a][b] = Map[b][a] = 1;
		Deg[a]++, Deg[b]++;
		U[min(a, b)]++;
		E[a].push_back(b);
		E[b].push_back(a);
	}
	for (i = 1; i <= n; i++) {
		sum += 1ll * U[i] * (Deg[i] - U[i]);
		Last[i] = i;
		w[i] = i;
	}
	printf("%lld\n", sum);
	scanf("%d", &Q);
	for (int T = n + 1; T <= n + Q; T++) {
		scanf("%d", &a);
		Add(a, -U[a]);
		if (T - Last[a] <= Deg[a] + 1) {
			for (j = Last[a] + 1; j < T; j++) {
				if (Last[w[j]] == j && Map[w[j]][a]) {
					Add(w[j], 1);
				}
			}
		}
		else {
			for (auto &x : E[a]) {
				if (Last[x] > Last[a]) {
					Add(x, 1);
				}
			}
		}
		Last[a] = T;
		w[T] = a;
		printf("%lld\n", sum);
	}
}


#include<cstdio>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
int n, m, U[101000], Deg[101000], w[301000], Last[101000], Q;
long long sum;
vector<int>E[101000];
map<int, int>Map[101000];
void Add(int a, int b) {
	sum -= (long long)U[a] * (Deg[a] - U[a]);
	U[a] += b;
	sum += (long long)U[a] * (Deg[a] - U[a]);
}
int main() {
	//freopen("input.txt", "r", stdin);
	int i ,a , b, j;
	scanf("%d%d", &n, &m);
	for (i = 0; i < m; i++) {
		scanf("%d%d", &a, &b);
		Map[a][b] = Map[b][a] = 1;
		Deg[a]++, Deg[b]++;
		U[min(a, b)]++;
		E[a].push_back(b);
		E[b].push_back(a);
	}
	for (i = 1; i <= n; i++) {
		sum += 1ll * U[i] * (Deg[i] - U[i]);
		Last[i] = i;
		w[i] = i;
	}
	printf("%lld\n", sum);
	scanf("%d", &Q);
	for (int T = n + 1; T <= n + Q; T++) {
		scanf("%d", &a);
		Add(a, -U[a]);
		if (T - Last[a] <= Deg[a]+1) {
			for (j = Last[a] + 1; j < T; j++) {
				if (Last[w[j]] == j && Map[w[j]][a]) {
					Add(w[j], 1);
				}
			}
		}
		Last[a] = T;
		w[T] = a;
		printf("%lld\n", sum);
	}
}


#include<cstdio>
#include<algorithm>
#include<vector>
#include<unordered_map>
using namespace std;
int n, m, U[101000], Deg[101000], w[301000], Last[101000], Q;
long long sum;
vector<int>E[101000];
unordered_map<int, int>Map[101000];
void Add(int a, int b) {
	sum -= (long long)U[a] * (Deg[a] - U[a]);
	U[a] += b;
	sum += (long long)U[a] * (Deg[a] - U[a]);
}
int main() {
	//freopen("input.txt", "r", stdin);
	int i, a, b, j;
	scanf("%d%d", &n, &m);
	for (i = 0; i < m; i++) {
		scanf("%d%d", &a, &b);
		Map[a][b] = Map[b][a] = 1;
		Deg[a]++, Deg[b]++;
		U[min(a, b)]++;
		E[a].push_back(b);
		E[b].push_back(a);
	}
	for (i = 1; i <= n; i++) {
		sum += 1ll * U[i] * (Deg[i] - U[i]);
		Last[i] = i;
		w[i] = i;
	}
	printf("%lld\n", sum);
	scanf("%d", &Q);
	for (int T = n + 1; T <= n + Q; T++) {
		scanf("%d", &a);
		Add(a, -U[a]);
		if (T - Last[a] <= Deg[a] + 1) {
			for (j = Last[a] + 1; j < T; j++) {
				if (Last[w[j]] == j && Map[w[j]][a]) {
					Add(w[j], 1);
				}
			}
		}
		else {
			for (auto &x : E[a]) {
				if (Last[x] > Last[a]) {
					Add(x, 1);
				}
			}
		}
		Last[a] = T;
		w[T] = a;
		printf("%lld\n", sum);
	}
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
ll n, m, ans = 0;
vector<vector<ll>> g;
vector<ll> d;
int main() {
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(0);cin.tie(0);
    cin >> n >> m;
    g.resize(n);
    d.resize(n);
    for(int i = 0; i < m; i++)
    {
        ll x, y;
        cin >> x >> y;
        x--;
        y--;
        if(x > y)
        {
            swap(x, y);
        }
        g[x].push_back(y);
        d[x]++;
        d[y]++;
    }
    for(int i = 0; i < n; i++)
    {
        ans += (d[i] - g[i].size()) * g[i].size();
    }
    cout << ans << endl;
    ll q;
    cin >> q;
    for(int i = 0; i < q; i++)
    {
        ll v;
        cin >> v;
        v--;
        ans -= (d[v] - g[v].size()) * g[v].size();
        for(int i = 0; i < g[v].size(); i++)
        {
            ll to = g[v][i];
            ans -= g[to].size();
            g[to].push_back(v);
            ans += d[to] - g[to].size();
        }
        g[v].clear();
        cout << ans << endl;
    }
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
ll n, m, ans = 0;
vector<set<ll>> a, b;
int main() {
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(0);cin.tie(0);
    cin >> n >> m;
    a.resize(n);
    b.resize(n);
    for(int i = 0; i < m; i++)
    {
        ll x, y;
        cin >> x >> y;
        x--;
        y--;
        if(x > y)
        {
            swap(x, y);
        }
        a[x].insert(y);
        b[y].insert(x);
    }
    for(int i = 0; i < n; i++)
    {
        ans += a[i].size() * b[i].size();
    }
    cout << ans << endl;
    ll q;
    cin >> q;
    for(int i = 0; i < q; i++)
    {
        ll v;
        cin >> v;
        v--;
        ans -= a[v].size() * b[v].size();
        for(auto x = a[v].begin(); x != a[v].end(); x++)
        {
            //cout << *x << "MEM" << endl;
            b[*x].erase(v);
            ans += b[*x].size();
            ans -= a[*x].size();
            a[*x].insert(v);
            b[v].insert(*x);
        }
        a[v].clear();
        cout << ans << endl;
    }
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
ll n, m, ans = 0;
vector<unordered_set<ll>> a, b;
int main() {
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(0);cin.tie(0);
    cin >> n >> m;
    a.resize(n);
    b.resize(n);
    for(int i = 0; i < m; i++)
    {
        ll x, y;
        cin >> x >> y;
        x--;
        y--;
        if(x > y)
        {
            swap(x, y);
        }
        a[x].insert(y);
        b[y].insert(x);
    }
    for(int i = 0; i < n; i++)
    {
        ans += a[i].size() * b[i].size();
    }
    cout << ans << endl;
    ll q;
    cin >> q;
    for(int i = 0; i < q; i++)
    {
        ll v;
        cin >> v;
        v--;
        ans -= a[v].size() * b[v].size();
        for(auto x = a[v].begin(); x != a[v].end(); x++)
        {
            //cout << *x << "MEM" << endl;
            b[*x].erase(v);
            ans += b[*x].size();
            ans -= a[*x].size();
            a[*x].insert(v);
            b[v].insert(*x);
        }
        a[v].clear();
        cout << ans << endl;
    }
}


#include<bits/stdc++.h>
#define int 			long long
#define FOR(i, a, b)	for (int i = a; i <= (int) b; ++i)
#define FORD(i, a, b)	for (int i = a; i >= (int) b; --i)
#define REP(i, a, b)	for (int i = a; i <  (int) b; ++i)
using namespace std;

typedef pair<int, int> ii;

const int N = 1e5 + 4, SQ = 324;
int n, m, Big_ID[N];
vector<int> Big, adj[N];
bool haveEdge[SQ][N];

int Sz[N], in[N], val[N], Match[N], res;

void update(int u, int New) {
	res -= (Sz[u] - in[u]) * in[u];
	in[u] = New;
	res += (Sz[u] - in[u]) * in[u];
}

void Answer_Query() {
	int Q, u;

	cin >> Q;
	FOR(Time, 1, Q) {
		cin >> u;
		update(u, adj[u].size());

		if ( (int) adj[u].size() <= SQ ) {
			for (int v : adj[u]) {
				if (val[v] < val[u]) continue;
				update(v, in[v]-1);
			}
		}
		else {
			int id = Big_ID[u];
			FOR(i, val[u]+1, n+Time-1) {
				if (Match[i] <= 0) continue;
				int v = Match[i];
				if (haveEdge[id][v]) update(v, in[v]-1);
			}
		}

		Match[val[u]] = 0;
		val[u] = n+Time;
		Match[val[u]] = u;

		cout << res << '\n';
	}
}

void sol() {
	FOR(i, 1, n) val[i] = i, Match[i] = i;

	FOR(u, 1, n) {
		Sz[u] = (int) adj[u].size();
		for (int v : adj[u]) {
			if (val[u] > val[v]) in[u]++;
		}
		res += (Sz[u] - in[u]) * in[u];
	}
	cout << res << '\n';

	Answer_Query();
}

#undef int
int main() {
#define int 			long long
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	if (fopen("input.txt", "r")) {
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	}

	cin >> n >> m;

	int u, v;
	FOR(i, 1, m) {
		cin >> u >> v;
		adj[u].push_back(v); adj[v].push_back(u);
	}

	FOR(i, 1, n) if ( (int) adj[u].size() > SQ ) {
		Big.push_back(u);
		Big_ID[u] = (int) Big.size();

		for (int v : adj[u]) haveEdge[ Big_ID[u] ][ v ] = true;
 	}

	sol();

	return 0;
}


#include<bits/stdc++.h>
#define int 			long long
#define FOR(i, a, b)	for (int i = a; i <= (int) b; ++i)
#define FORD(i, a, b)	for (int i = a; i >= (int) b; --i)
#define REP(i, a, b)	for (int i = a; i <  (int) b; ++i)
using namespace std;

typedef pair<int, int> ii;

const int N = 1e5 + 4, SQ = 324;
int n, m, Big_ID[N];
vector<int> adj[N];
bool haveEdge[2*SQ][N];

int Sz[N], in[N], val[N], Match[2*N], res;

void update(int u, int New) {
	res -= (Sz[u] - in[u]) * in[u];
	in[u] = New;
	res += (Sz[u] - in[u]) * in[u];
}

void Answer_Query() {
	int Q, u;

	cin >> Q;
	FOR(Time, 1, Q) {
		cin >> u;
		update(u, adj[u].size());

		if ( (int) adj[u].size() <= SQ ) {
			for (int v : adj[u]) {
				if (val[v] < val[u]) continue;
				update(v, in[v]-1);
			}
		}
		else {
			int id = Big_ID[u];
			FOR(i, val[u]+1, n+Time-1) {
				if (Match[i] <= 0) continue;
				int v = Match[i];
				if (haveEdge[id][v]) update(v, in[v]-1);
			}
		}

		Match[val[u]] = 0;
		val[u] = n+Time;
		Match[val[u]] = u;

		cout << res << '\n';
	}
}

void sol() {
	FOR(i, 1, n) val[i] = i, Match[i] = i;

	FOR(u, 1, n) {
		Sz[u] = (int) adj[u].size();
		for (int v : adj[u]) {
			if (val[u] > val[v]) in[u]++;
		}
		res += (Sz[u] - in[u]) * in[u];
	}
	cout << res << '\n';

	Answer_Query();
}

#undef int
int main() {
#define int 			long long
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	if (fopen("input.txt", "r")) {
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	}

	cin >> n >> m;

	int u, v;
	FOR(i, 1, m) {
		cin >> u >> v;
		adj[u].push_back(v); adj[v].push_back(u);
	}

	int numBig = 0;
	FOR(u, 1, n) if ( (int) adj[u].size() > SQ ) {
		Big_ID[u] = ++numBig;
		// if (numBig >= SQ) {
		// 	cout << "# " << numBig << '\n';
		// 	exit(0);
		// }
		for (int v : adj[u]) haveEdge[ Big_ID[u] ][ v ] = true;
 	}

	sol();

	return 0;
}


#include<bits/stdc++.h>
#define int 			long long
#define FOR(i, a, b)	for (int i = a; i <= (int) b; ++i)
#define FORD(i, a, b)	for (int i = a; i >= (int) b; --i)
#define REP(i, a, b)	for (int i = a; i <  (int) b; ++i)
using namespace std;

typedef pair<int, int> ii;

const int N = 1e5 + 4, SQ = 324;
int n, m, Big_ID[N];
vector<int> Big, adj[N];
bool haveEdge[SQ][N];

int Sz[N], in[N], val[N], Match[2*N], res;

void update(int u, int New) {
	res -= (Sz[u] - in[u]) * in[u];
	in[u] = New;
	res += (Sz[u] - in[u]) * in[u];
}

void Answer_Query() {
	int Q, u;

	cin >> Q;
	FOR(Time, 1, Q) {
		cin >> u;
		update(u, adj[u].size());

		if ( (int) adj[u].size() <= SQ ) {
			for (int v : adj[u]) {
				if (val[v] < val[u]) continue;
				update(v, in[v]-1);
			}
		}
		else {
			int id = Big_ID[u];
			FOR(i, val[u]+1, n+Time-1) {
				if (Match[i] <= 0) continue;
				int v = Match[i];
				if (haveEdge[id][v]) update(v, in[v]-1);
			}
		}

		Match[val[u]] = 0;
		val[u] = n+Time;
		Match[val[u]] = u;

		cout << res << '\n';
	}
}

void sol() {
	FOR(i, 1, n) val[i] = i, Match[i] = i;

	FOR(u, 1, n) {
		Sz[u] = (int) adj[u].size();
		for (int v : adj[u]) {
			if (val[u] > val[v]) in[u]++;
		}
		res += (Sz[u] - in[u]) * in[u];
	}
	cout << res << '\n';

	Answer_Query();
}

#undef int
int main() {
#define int 			long long
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	if (fopen("input.txt", "r")) {
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	}

	cin >> n >> m;

	int u, v;
	FOR(i, 1, m) {
		cin >> u >> v;
		adj[u].push_back(v); adj[v].push_back(u);
	}

	FOR(u, 1, n) if ( (int) adj[u].size() > SQ ) {
		Big.push_back(u);
		Big_ID[u] = (int) Big.size();

		for (int v : adj[u]) haveEdge[ Big_ID[u] ][ v ] = true;
 	}

	sol();

	return 0;
}


#include<bits/stdc++.h>
#define int 			long long
#define FOR(i, a, b)	for (int i = a; i <= (int) b; ++i)
#define FORD(i, a, b)	for (int i = a; i >= (int) b; --i)
#define REP(i, a, b)	for (int i = a; i <  (int) b; ++i)
using namespace std;

typedef pair<int, int> ii;

const int N = 1e5 + 4, SQ = 324;
int n, m, Big_ID[N];
vector<int> Big, adj[N];
bool haveEdge[SQ][N];

int Sz[N], in[N], val[N], Match[N], res;

void update(int u, int New) {
	res -= (Sz[u] - in[u]) * in[u];
	in[u] = New;
	res += (Sz[u] - in[u]) * in[u];
}

void Answer_Query() {
	int Q, u;

	cin >> Q;
	FOR(Time, 1, Q) {
		cin >> u;
		update(u, adj[u].size());

		if ( (int) adj[u].size() <= SQ ) {
			for (int v : adj[u]) {
				if (val[v] < val[u]) continue;
				update(v, in[v]-1);
			}
		}
		else {
			int id = Big_ID[u];
			FOR(i, val[u]+1, n+Time-1) {
				if (Match[i] <= 0) continue;
				int v = Match[i];
				if (haveEdge[id][v]) update(v, in[v]-1);
			}
		}

		Match[val[u]] = 0;
		val[u] = n+Time;
		Match[val[u]] = u;

		cout << res << '\n';
	}
}

void sol() {
	FOR(i, 1, n) val[i] = i, Match[i] = i;

	FOR(u, 1, n) {
		Sz[u] = (int) adj[u].size();
		for (int v : adj[u]) {
			if (val[u] > val[v]) in[u]++;
		}
		res += (Sz[u] - in[u]) * in[u];
	}
	cout << res << '\n';

	Answer_Query();
}

#undef int
int main() {
#define int 			long long
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	if (fopen("input.txt", "r")) {
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	}

	cin >> n >> m;

	int u, v;
	FOR(i, 1, m) {
		cin >> u >> v;
		adj[u].push_back(v); adj[v].push_back(u);
	}

	FOR(u, 1, n) if ( (int) adj[u].size() > SQ ) {
		Big.push_back(u);
		Big_ID[u] = (int) Big.size();

		for (int v : adj[u]) haveEdge[ Big_ID[u] ][ v ] = true;
 	}

	sol();

	return 0;
}


#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<iomanip>
#include<set>
using namespace std ;

#define MAXN 100007

int n , m ;
int a[ MAXN ] ;
vector < int > v[ MAXN ] ;
long long in[ MAXN ] ;
long long out[ MAXN ] ;

long long ans = 0 ;

void update ( int vertex , int nw ) {
    int sz = v[ vertex ].size ( ) ;
    for ( int i = 0 ; i < sz ; ++ i ) {
        long long old = in[ v[ vertex ][ i ] ] * out[ v[ vertex ][ i ] ] ;
        if ( a[ vertex ] < a[ v[ vertex ][ i ] ] ) {
            -- out[ v[ vertex ][ i ] ] ;
            ++ in[ v[ vertex ][ i ] ] ;
        }
        ans += in[ v[ vertex ][ i ] ] * out[ v[ vertex ][ i ] ] - old ;
    }
    ans -= in[ vertex ] * out[ vertex ] ;
    in[ vertex ] = 0 ;
    out[ vertex ] = sz ;
    a[ vertex ] = nw ;
}

void input ( ) {
    scanf ( "%d%d" , &n , &m ) ;
    for ( int i = 1 ; i <= m ; ++ i ) {
        int x , y ;
        scanf ( "%d%d" , &x , &y ) ;
        v[ x ].push_back ( y ) ;
        v[ y ].push_back ( x ) ;
        ++ in[ min ( x , y ) ] ;
        ++ out[ max ( x , y ) ] ;
    }
    for ( int i = 1 ; i <= n ; ++ i ) {
        a[ i ] = i ;
    }
}

void solve ( ) {
    for ( int i = 1 ; i <= n ; ++ i ) {
        ans += in[ i ] * out[ i ] ;
    }
    int q ;
    scanf ( "%d" , &q ) ;
    int tp = n ;
    printf ( "%I64d\n" , ans ) ;
    while ( q -- ) {
        int x ;
        scanf ( "%d" , &x ) ;
        update ( x , ++ tp ) ;
        printf ( "%I64d\n" , ans ) ;
    }
}

int main ( ) {
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    input ( ) ;
    solve ( ) ;
    return 0 ;
}


#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<iomanip>
#include<set>
using namespace std ;

#define MAXN 100007

int n , m ;
int a[ MAXN ] ;
vector < int > v[ MAXN ] ;
long long in[ MAXN ] ;
long long out[ MAXN ] ;

long long ans = 0 ;

void update ( int vertex , int nw ) {
    int sz = v[ vertex ].size ( ) ;
    for ( int i = 0 ; i < sz ; ++ i ) {
        long long old = in[ v[ vertex ][ i ] ] * out[ v[ vertex ][ i ] ] ;
        -- out[ v[ vertex ][ i ] ] ;
        ++ in[ v[ vertex ][ i ] ] ;
        ans += in[ v[ vertex ][ i ] ] * out[ v[ vertex ][ i ] ] - old ;
        v[ v[ vertex ][ i ] ].push_back ( vertex ) ;
    }
    ans -= in[ vertex ] * out[ vertex ] ;
    out[ vertex ] += in[ vertex ] ;
    in[ vertex ] = 0 ;
    a[ vertex ] = nw ;
    v[ vertex ].clear ( ) ;
}

void input ( ) {
    scanf ( "%d%d" , &n , &m ) ;
    for ( int i = 1 ; i <= m ; ++ i ) {
        int x , y ;
        scanf ( "%d%d" , &x , &y ) ;
        if ( x > y ) { swap ( x , y ) ; }
        v[ x ].push_back ( y ) ;
        ++ in[ x ] ;
        ++ out[ y ] ;
    }
    for ( int i = 1 ; i <= n ; ++ i ) {
        a[ i ] = i ;
    }
}

void solve ( ) {
    for ( int i = 1 ; i <= n ; ++ i ) {
        ans += in[ i ] * out[ i ] ;
    }
    int q ;
    scanf ( "%d" , &q ) ;
    int tp = n ;
    printf ( "%I64d\n" , ans ) ;
    while ( q -- ) {
        int x ;
        scanf ( "%d" , &x ) ;
        update ( x , ++ tp ) ;
        printf ( "%I64d\n" , ans ) ;
    }
}

int main ( ) {
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    input ( ) ;
    solve ( ) ;
    return 0 ;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5 + 7;
const int SQ_C = 55;

vector<int> adj[MAXN];
int n, m;
long long ans = 0;
pair<long long, long long> p[MAXN];
bool used[MAXN];
long long pos[MAXN];
bool one_time[MAXN];

set<pair<int, int> > e;

long long quer[MAXN];

void refresh(){
	for(int i = 1; i <= n; ++i){
		used[i] = false;
	}
}

bool check(int u, int v){
	if(u > v){
		swap(u, v);
	}

	if(e.count({u, v})){
		return true;
	}

	return false;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n >> m;

	for(int i = 0; i < m; ++i){
		int u, v;

		cin >> u >> v;

		adj[u].push_back(v);
		adj[v].push_back(u);

		if(u > v){
			swap(u, v);
		}

		++p[u].second;
		++p[v].first;

		e.insert({u, v});
	}

	for(int i = 1; i <= n; ++i){
		ans += p[i].first * p[i].second;
		pos[i] = i - 1;
	}

	int q;

	cin >> q;

	cout << ans << "\n";

	for(int i = 0; i < q; ++i){
		if(i % SQ_C == 0){
			refresh();
		}

		int v;

		cin >> v;
		quer[i] = v;

		if(!used[v]){
			for(int to: adj[v]){
				if(pos[to] > pos[v]){
					ans -= p[to].first * p[to].second;
					--p[to].first;
					++p[to].second;
					ans += p[to].first * p[to].second;
				}
			}
			ans -= p[v].first * p[v].second;
			p[v].first = (long long)adj[v].size();
			p[v].second = 0;

			used[v] = true;
			pos[v] = i + n;
		}
		else{
			int rem = i % SQ_C;
			if(rem < 0)
				rem += SQ_C;
			if(rem >= SQ_C)
				rem -= SQ_C;

			int pr = i - rem;

			for(int j = pr; j < i; ++j){
				int to = quer[j];
				if(one_time[to]){
					continue;
				}
				one_time[to] = true;
				if(check(v, to)){
					if(pos[to] > pos[v]){
						ans -= p[to].first * p[to].second;
						--p[to].first;
						++p[to].second;
						ans += p[to].first * p[to].second;
					}
				}
			}
			for(int j = pr; j < i; ++j){
				int to = quer[j];
				one_time[to] = false;
			}

			ans -= p[v].first * p[v].second;
			p[v].first = (long long)adj[v].size();
			p[v].second = 0;

			used[v] = true;
			pos[v] = i + n;
		}

		cout << ans << "\n";
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5 + 7;
const int SQ_C = 60;

vector<int> adj[MAXN];
int n, m;
long long ans = 0;
pair<long long, long long> p[MAXN];
bool used[MAXN];
long long pos[MAXN];

set<pair<int, int> > e;

long long quer[MAXN];

void refresh(){
	for(int i = 1; i <= n; ++i){
		used[i] = false;
	}
}

bool check(int u, int v){
	if(u > v){
		swap(u, v);
	}

	if(e.count({u, v})){
		return true;
	}

	return false;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n >> m;

	for(int i = 0; i < m; ++i){
		int u, v;

		cin >> u >> v;

		adj[u].push_back(v);
		adj[v].push_back(u);

		if(u > v){
			swap(u, v);
		}

		++p[u].second;
		++p[v].first;

		e.insert({u, v});
	}

	for(int i = 1; i <= n; ++i){
		ans += p[i].first * p[i].second;
		pos[i] = i - 1;
	}

	int q;

	cin >> q;

	cout << ans << "\n";

	for(int i = 0; i < q; ++i){
		if(i % SQ_C == 0){
			refresh();
		}

		int v;

		cin >> v;
		quer[i] = v;

		if(!used[v]){
			for(int to: adj[v]){
				if(pos[to] > pos[v]){
					ans -= p[to].first * p[to].second;
					--p[to].first;
					++p[to].second;
					ans += p[to].first * p[to].second;
				}
			}
			ans -= p[v].first * p[v].second;
			p[v].first = (long long)adj[v].size();
			p[v].second = 0;

			used[v] = true;
			pos[v] = i + n;
		}
		else{
			int rem = i % SQ_C;
			if(rem < 0)
				rem += SQ_C;
			if(rem >= SQ_C)
				rem -= SQ_C;

			int pr = i - rem;

			for(int to = pr; to < i; ++to){
				if(check(v, to)){
					if(pos[to] > pos[v]){
						ans -= p[to].first * p[to].second;
						--p[to].first;
						++p[to].second;
						ans += p[to].first * p[to].second;
					}
				}
			}

			ans -= p[v].first * p[v].second;
			p[v].first = (long long)adj[v].size();
			p[v].second = 0;

			used[v] = true;
			pos[v] = i + n;
		}

		cout << ans << "\n";
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long Long;

const Long MX = 1e5 + 10;

vector<Long> adj[MX];
vector<Long> in[MX];
Long out[MX];

Long nuevo(Long val, Long ac){
	Long a = in[val].size();
	Long b = out[val];
	ac -= a*b;
	for(Long x : in[val]){
		ac -= Long(in[x].size());
		out[x]--;
		ac += out[x];
		in[x].push_back(val);
		out[val]++;
	}
	in[val].clear();
	return ac;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout.precision(10);
	cout << fixed;

	Long n, k, x, y;
	cin >> n >> k;
	for(Long i = 0; i < k; i++){
		cin >> x >> y;
		in[min(x,y)].push_back(max(x,y));
		out[max(x,y)]++;
	}

	Long ac = 0;
	for(Long i = 1; i <= n; i++){
		Long a = in[i].size();
		Long b = out[i];
		ac +=  a*b;
	}

	cout << ac << "\n";
	Long q;
	cin >> q;
	for(Long i = 0; i < q; i++){
		cin >> x;
		ac = nuevo(x,ac);
		cout << ac << "\n";
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long Long;

const Long MX = 1e5 + 10;

vector<Long> adj[MX];
set<Long> in[MX];
set<Long> out[MX];

Long nuevo(Long val, Long ac){
	Long a = in[val].size();
	Long b = out[val].size();
	ac -= a*b;
	vector<Long> nuevos;
	for(Long x : in[val]){
		nuevos.push_back(x);
		ac -= Long(in[x].size());
	}

	for(Long x : in[val]){
		out[x].erase(val);
	}
	in[val].clear();

	for(Long x : nuevos){
		in[x].insert(val);
		out[val].insert(x);
	}

	for(Long x : nuevos){
		ac += Long(out[x].size());
	}
	return ac;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout.precision(10);
	cout << fixed;

	Long n, k, x, y;
	cin >> n >> k;
	for(Long i = 0; i < k; i++){
		cin >> x >> y;
		in[min(x,y)].insert(max(x,y));
		out[max(x,y)].insert(min(x,y));
	}

	Long ac = 0;
	for(Long i = 1; i <= n; i++){
		Long a = in[i].size();
		Long b = out[i].size();
		ac +=  a*b;
	}

	cout << ac << "\n";
	Long q;
	cin >> q;
	for(Long i = 0; i < q; i++){
		cin >> x;
		ac = nuevo(x,ac);
		cout << ac << "\n";
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long Long;

const Long MX = 1e5 + 10;

vector<Long> adj[MX];
unordered_set<Long> in[MX];
unordered_set<Long> out[MX];

Long nuevo(Long val, Long ac){
	Long a = in[val].size();
	Long b = out[val].size();
	ac -= a*b;
	for(Long x : in[val]){
		ac -= Long(in[x].size());
		out[x].erase(val);
		ac += Long(out[x].size());
		in[x].insert(val);
		out[val].insert(x);
	}
	in[val].clear();

	/*for(Long i = 1; i <= 4; i++){
		cout << "IN ";
		for(Long x : in[i]){
			cout << x << " ";
		}
		cout << endl;
		cout << "OUT ";
		for(Long x : out[i]){
			cout << x << " ";
		}
		cout << endl;
	}*/
	return ac;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout.precision(10);
	cout << fixed;

	Long n, k, x, y;
	cin >> n >> k;
	for(Long i = 0; i < k; i++){
		cin >> x >> y;
		in[min(x,y)].insert(max(x,y));
		out[max(x,y)].insert(min(x,y));
	}

	Long ac = 0;
	for(Long i = 1; i <= n; i++){
		Long a = in[i].size();
		Long b = out[i].size();
		ac +=  a*b;
	}

	cout << ac << "\n";
	Long q;
	cin >> q;
	for(Long i = 0; i < q; i++){
		cin >> x;
		ac = nuevo(x,ac);
		cout << ac << "\n";
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long Long;

const Long MX = 1e5 + 10;

vector<Long> adj[MX];
unordered_set<Long> in[MX];
Long out[MX];

Long nuevo(Long val, Long ac){
	Long a = in[val].size();
	Long b = out[val];
	ac -= a*b;
	for(Long x : in[val]){
		ac -= Long(in[x].size());
		out[x]--;
		ac += out[x];
		in[x].insert(val);
		out[val]++;
	}
	in[val].clear();

	/*for(Long i = 1; i <= 4; i++){
		cout << "IN ";
		for(Long x : in[i]){
			cout << x << " ";
		}
		cout << endl;
		cout << "OUT ";
		for(Long x : out[i]){
			cout << x << " ";
		}
		cout << endl;
	}*/
	return ac;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout.precision(10);
	cout << fixed;

	Long n, k, x, y;
	cin >> n >> k;
	for(Long i = 0; i < k; i++){
		cin >> x >> y;
		in[min(x,y)].insert(max(x,y));
		out[max(x,y)]++;
	}

	Long ac = 0;
	for(Long i = 1; i <= n; i++){
		Long a = in[i].size();
		Long b = out[i];
		ac +=  a*b;
	}

	cout << ac << "\n";
	Long q;
	cin >> q;
	for(Long i = 0; i < q; i++){
		cin >> x;
		ac = nuevo(x,ac);
		cout << ac << "\n";
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long Long;

const Long MX = 1e5 + 10;

vector<Long> adj[MX];
unordered_set<Long> in[MX];
unordered_set<Long> out[MX];

Long nuevo(Long val, Long ac){
	Long a = in[val].size();
	Long b = out[val].size();
	ac -= a*b;
	vector<Long> nuevos;
	for(Long x : in[val]){
		nuevos.push_back(x);
		ac -= Long(in[x].size());
	}

	for(Long x : in[val]){
		out[x].erase(val);
	}
	in[val].clear();

	for(Long x : nuevos){
		in[x].insert(val);
		out[val].insert(x);
	}

	for(Long x : nuevos){
		ac += Long(out[x].size());
	}
	return ac;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout.precision(10);
	cout << fixed;

	Long n, k, x, y;
	cin >> n >> k;
	for(Long i = 0; i < k; i++){
		cin >> x >> y;
		in[min(x,y)].insert(max(x,y));
		out[max(x,y)].insert(min(x,y));
	}

	Long ac = 0;
	for(Long i = 1; i <= n; i++){
		Long a = in[i].size();
		Long b = out[i].size();
		ac +=  a*b;
	}

	cout << ac << "\n";
	Long q;
	cin >> q;
	for(Long i = 0; i < q; i++){
		cin >> x;
		ac = nuevo(x,ac);
		cout << ac << "\n";
	}
	return 0;
}


#include<bits/stdc++.h>
#define MAXN 100010
#define ll long long
using namespace std;
unordered_set<int> ve[MAXN], vd[MAXN];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	ll ans = 0;

	for(int i = 0; i < m; i++){
		int a, b;
		cin >> a >> b;
		if(a > b) swap(a, b);
		vd[a].insert(b);
		ve[b].insert(a);
	}

	for(int i = 1; i <= n; i++)
		ans += (ll) vd[i].size() * (ll) ve[i].size();

	int q;
	cin >> q;
	cout << ans << "\n";
	while(q--){
		int j;
		cin >> j;
		ans -= (ll)ve[j].size() * vd[j].size();

		for(auto &u : vd[j]){
			ve[j].insert(u);
			ve[u].erase(j);
			ans += ve[u].size();
			ans -= vd[u].size();
			vd[u].insert(j);
		}
		vd[j].clear();

		cout << ans << "\n";
	}
	return 0;
}


#include<bits/stdc++.h>
#define MAXN 100010
#define ll long long
using namespace std;
vector<int> vd[MAXN];
ll ve[MAXN];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	ll ans = 0;

	for(int i = 0; i < m; i++){
		int a, b;
		cin >> a >> b;
		if(a > b) swap(a, b);
		vd[a].push_back(b);
		ve[b]++;
	}

	for(int i = 1; i <= n; i++)
		ans += (ll) vd[i].size() * ve[i];

	int q;
	cin >> q;
	cout << ans << "\n";
	while(q--){
		int j;
		cin >> j;
		ans -= ve[j] * (ll)vd[j].size();

		for(auto &u : vd[j]){
			ve[j]++;
			ve[u]--;
			ans += ve[u];
			ans -= vd[u].size();
			vd[u].push_back(j);
		}
		vd[j].clear();

		cout << ans << "\n";
	}
	return 0;
}


#include<bits/stdc++.h>
#define MAXN 100010
#define ll long long
using namespace std;
set<int> ve[MAXN], vd[MAXN];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	ll ans = 0;

	for(int i = 0; i < m; i++){
		int a, b;
		cin >> a >> b;
		if(a > b) swap(a, b);
		vd[a].insert(b);
		ve[b].insert(a);
	}

	for(int i = 1; i <= n; i++)
		ans += (ll) vd[i].size() * (ll) ve[i].size();

	int q;
	cin >> q;
	cout << ans << "\n";
	while(q--){
		int j;
		cin >> j;
		ans -= (ll)ve[j].size() * vd[j].size();

		for(auto &u : vd[j]){
			ve[j].insert(u);
			ve[u].erase(j);
			ans += ve[u].size();
			ans -= vd[u].size();
			vd[u].insert(j);
		}
		vd[j].clear();

		cout << ans << "\n";
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 100100;
int n, m, q;
vector<int> g[N];
ll deg[N];
ll ANS;

ll get(int v) {
	return (deg[v] - (ll)g[v].size()) * (ll)g[v].size();
}

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d%d", &n, &m);
	const int B = 316;
	int knt = 0;

	for (int i = 0; i < m; i++) {
		int v, u;
		scanf("%d%d", &v, &u);
		if (v > u) swap(v, u);
		g[v].push_back(u);
		deg[v]++;
		deg[u]++;

		if (deg[v] == B)
		knt++;

		if (deg[u] == B)
		knt++;
	}

	assert(knt < 100);

	for (int i = 1; i <= n; i++)
		ANS += get(i);
	printf("%lld\n", ANS);
	scanf("%d", &q);
	while(q--) {
		int v;
		scanf("%d", &v);
		while(!g[v].empty()) {
			int u = g[v].back();
			ANS -= get(v) + get(u);
			g[v].pop_back();
			g[u].push_back(v);
			ANS += get(v) + get(u);
		}
		printf("%lld\n", ANS);
	}

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 100100;
int n, m, q;
vector<int> g[N];
ll deg[N];
ll ANS;

ll get(int v) {
	return (deg[v] - (ll)g[v].size()) * (ll)g[v].size();
}

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d%d", &n, &m);
	const int B = 316;
	int knt = 0;

	for (int i = 0; i < m; i++) {
		int v, u;
		scanf("%d%d", &v, &u);
		if (v > u) swap(v, u);
		g[v].push_back(u);
		deg[v]++;
		deg[u]++;

		if (deg[v] == B)
		knt++;

		if (deg[u] == B)
		knt++;
	}

	assert(knt < 200);

	for (int i = 1; i <= n; i++)
		ANS += get(i);
	printf("%lld\n", ANS);
	scanf("%d", &q);
	while(q--) {
		int v;
		scanf("%d", &v);
		while(!g[v].empty()) {
			int u = g[v].back();
			ANS -= get(v) + get(u);
			g[v].pop_back();
			g[u].push_back(v);
			ANS += get(v) + get(u);
		}
		printf("%lld\n", ANS);
	}

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 100100;
int n, m, q;
vector<int> g[N];
ll deg[N];
ll ANS;

ll get(int v) {
	return (deg[v] - (ll)g[v].size()) * (ll)g[v].size();
}

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d%d", &n, &m);
	const int B = 316;
	int knt = 0;

	for (int i = 0; i < m; i++) {
		int v, u;
		scanf("%d%d", &v, &u);
		if (v > u) swap(v, u);
		g[v].push_back(u);
		deg[v]++;
		deg[u]++;

		if (deg[v] == B)
		knt++;

		if (deg[u] == B)
		knt++;
	}

	assert(knt < B);

	for (int i = 1; i <= n; i++)
		ANS += get(i);
	printf("%lld\n", ANS);
	scanf("%d", &q);
	while(q--) {
		int v;
		scanf("%d", &v);
		while(!g[v].empty()) {
			int u = g[v].back();
			ANS -= get(v) + get(u);
			g[v].pop_back();
			g[u].push_back(v);
			ANS += get(v) + get(u);
		}
		printf("%lld\n", ANS);
	}

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 100100;
int n, m, q;
vector<int> g[N];
ll deg[N];
ll ANS;

ll get(int v) {
	return (deg[v] - (ll)g[v].size()) * (ll)g[v].size();
}

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d%d", &n, &m);
	const int B = 316;
	int knt = 0;

	for (int i = 0; i < m; i++) {
		int v, u;
		scanf("%d%d", &v, &u);
		if (v > u) swap(v, u);
		g[v].push_back(u);
		deg[v]++;
		deg[u]++;

		if (deg[v] == B)
		knt++;

		if (deg[u] == B)
		knt++;
	}

	assert(knt < 2 * B);

	for (int i = 1; i <= n; i++)
		ANS += get(i);
	printf("%lld\n", ANS);
	scanf("%d", &q);
	while(q--) {
		int v;
		scanf("%d", &v);
		while(!g[v].empty()) {
			int u = g[v].back();
			ANS -= get(v) + get(u);
			g[v].pop_back();
			g[u].push_back(v);
			ANS += get(v) + get(u);
		}
		printf("%lld\n", ANS);
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)1e5 + 1;
const int B = 300;
vector<int> T[N];
vector<int> R[N];
ll deg[N];
ll b[N];
ll u[N], v[N];

vector<ll> ask;
ll did[N];

ll f[B + 55];

void add(int li, ll di){
  f[li] += di;
}

ll sal[N];

int main(){
  fastIO;
  ll n, m;
  cin >> n >> m;
  for(int i = 0 ;i  <m ; i ++ ){
    cin >> u[i] >> v[i];
    deg[u[i]] ++ ;
    deg[v[i]] ++ ;
    if(u[i] > v[i]) swap(u[i], v[i]);
      b[v[i]] ++ ;
    T[u[i]].push_back(v[i]);
    T[v[i]].push_back(u[i]);
  }
  ll res = 0;
  for(int i = 1; i <= n; i ++ ){
    res += (deg[i] - b[i]) * 1ll * b[i];
    sal[i] = i;
  }
  cout << res << "\n";
  int q;
  cin >> q;
  int l=0,r;
  int vr;
  while(l < q){
    r = min(q-1, l+B-1);
    for(int i = 0 ;i <= B;i ++ )
      f[i] = 0;
    ask.clear();
    for(int i = 1; i <= n; i ++ ){
      did[i] = -1;
      R[i].clear();
    }
    for(int t = l; t <= r; t ++ ){
      cin >> vr;
      ask.push_back(vr);
    }
    for(int i = (int)ask.size() - 1; i >= 0 ; i -- ){
      did[ask[i]] = i;
    }
    for(int i = 1; i <= n; i ++ ){
      if(did[i] != -1){
        for(auto x : T[i]){
          if(did[x] != -1){
            R[i].push_back(x);
          }
        }
      }
    }
    for(int i = 1; i <= n; i ++ ){
      if(did[i] != -1) continue;
      vector<int> tt;
      for(auto x : T[i]){
        if(did[x] != -1){
          if(sal[i] > sal[x])
            tt.push_back(did[x]);
        }
      }
      sort(tt.begin(), tt.end());
      for(auto x : tt){
        add(x, -(deg[i]-b[i])*1ll*b[i]);
        b[i] -- ;
        add(x, (deg[i]-b[i])*1ll*b[i]);
      }
    }
    for(int i = 0 ; i < ask.size(); i ++ ){
      add(i, -(deg[ask[i]]-b[ask[i]])*1ll*b[ask[i]]);
      b[ask[i]] = deg[ask[i]];
      for(auto x : R[ask[i]]){
        if(sal[ask[i]] < sal[x]){
          add(i, -(deg[x]-b[x])*1ll*b[x]);
          b[x] -- ;
          add(i, (deg[x]-b[x])*1ll*b[x]);
        }
      }
      sal[ask[i]] = n + l + i + 1;
    }

    for(int i = l ; i <= r; i ++ ){
      res += f[i];
      cout << res << "\n";
    }
    for(int i = 1; i <= n; i ++ ){
      b[i] = 0;
    }
    for(int i = 0 ; i < m ; i ++ ){
      if(u[i] < v[i]){
        b[v[i]] ++ ;
      }
      else{
        b[u[i]] ++ ;
      }
    }
    res = 0;
    for(int i = 1; i <= n; i ++ ){
      res += (deg[i] - b[i]) * 1ll * b[i];
    }
    l += B;
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)1e5 + 1;
const int B = 300;
vector<int> T[N];
vector<int> R[N];
ll deg[N];
ll b[N];
ll u[N], v[N];

vector<ll> ask;
ll did[N];

ll f[B + 55];

void add(int li, ll di){
  f[li] += di;
}

ll sal[N];

int main(){
  fastIO;
  ll n, m;
  cin >> n >> m;
  for(int i = 0 ;i  <m ; i ++ ){
    cin >> u[i] >> v[i];
    deg[u[i]] ++ ;
    deg[v[i]] ++ ;
    if(u[i] > v[i]) swap(u[i], v[i]);
      b[v[i]] ++ ;
    T[u[i]].push_back(v[i]);
    T[v[i]].push_back(u[i]);
  }
  ll res = 0;
  for(int i = 1; i <= n; i ++ ){
    res += (deg[i] - b[i]) * 1ll * b[i];
    sal[i] = i;
  }
  cout << res << "\n";
  int q;
  cin >> q;
  int l=0,r;
  int v;
  while(l < q){
    r = min(q-1, l+B-1);
    for(int i = 0 ;i <= B;i ++ )
      f[i] = 0;
    ask.clear();
    for(int i = 1; i <= n; i ++ ){
      did[i] = -1;
      R[i].clear();
    }
    for(int t = l; t <= r; t ++ ){
      cin >> v;
      ask.push_back(v);
    }
    for(int i = (int)ask.size() - 1; i >= 0 ; i -- ){
      did[ask[i]] = i;
    }
    for(int i = 1; i <= n; i ++ ){
      if(did[i] != -1){
        for(auto x : T[i]){
          if(did[x] != -1){
            R[i].push_back(x);
          }
        }
      }
    }
    for(int i = 1; i <= n; i ++ ){
      if(did[i] != -1) continue;
      vector<int> tt;
      for(auto x : T[i]){
        if(did[x] != -1){
          if(sal[i] > sal[x])
            tt.push_back(did[x]);
        }
      }
      sort(tt.begin(), tt.end());
      for(auto x : tt){
        add(x, -(deg[i]-b[i])*1ll*b[i]);
        b[i] -- ;
        add(x, (deg[i]-b[i])*1ll*b[i]);
      }
    }
    for(int i = 0 ; i < ask.size(); i ++ ){
      add(i, -(deg[ask[i]]-b[ask[i]])*1ll*b[ask[i]]);
      b[ask[i]] = deg[ask[i]];
      for(auto x : R[ask[i]]){
        if(sal[ask[i]] < sal[x]){
          add(i, -(deg[x]-b[x])*1ll*b[x]);
          b[x] -- ;
          add(i, (deg[x]-b[x])*1ll*b[x]);
        }
      }
      sal[ask[i]] = n + l + i + 1;
    }

    for(int i = l ; i <= r; i ++ ){
      res += f[i];
      cout << res << "\n";
    }
    for(int i = 1; i <= n; i ++ ){
      b[i] = 0;
    }
    for(int i = 0 ; i < m ; i ++ ){
      if(sal[u[i]] < sal[v[i]]){
        b[u[i]] ++ ;
      }
      else{
        b[v[i]] ++ ;
      }
    }
    res = 0;
    for(int i = 1; i <= n; i ++ ){
      res += (deg[i] - b[i]) * 1ll * b[i];
    }
    l += B;
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)1e5 + 1;
const int B = 300;
vector<int> T[N];
vector<int> R[N];
ll deg[N];
ll b[N];
ll u[N], v[N];

vector<ll> ask;
ll did[N];

ll f[B + 55];

void add(int li, ll di){
  f[li] += di;
}

ll sal[N];

int main(){
  fastIO;
  ll n, m;
  cin >> n >> m;
  for(int i = 0 ;i  <m ; i ++ ){
    cin >> u[i] >> v[i];
    deg[u[i]] ++ ;
    deg[v[i]] ++ ;
    if(u[i] > v[i]) swap(u[i], v[i]);
      b[v[i]] ++ ;
    T[u[i]].push_back(v[i]);
    T[v[i]].push_back(u[i]);
  }
  ll res = 0;
  for(int i = 1; i <= n; i ++ ){
    res += (deg[i] - b[i]) * 1ll * b[i];
    sal[i] = i;
  }
  cout << res << "\n";
  int q;
  cin >> q;
  int l=0,r;
  int v;
  while(l < q){
    r = min(q-1, l+B-1);
    for(int i = 0 ;i <= B;i ++ )
      f[i] = 0;
    ask.clear();
    for(int i = 1; i <= n; i ++ ){
      did[i] = -1;
      R[i].clear();
    }
    for(int t = l; t <= r; t ++ ){
      cin >> v;
      ask.push_back(v);
    }
    for(int i = (int)ask.size() - 1; i >= 0 ; i -- ){
      did[ask[i]] = i;
    }
    for(int i = 1; i <= n; i ++ ){
      if(did[i] != -1){
        for(auto x : T[i]){
          if(did[x] != -1){
            R[i].push_back(x);
          }
        }
      }
    }
    for(int i = 1; i <= n; i ++ ){
      if(did[i] != -1) continue;
      vector<int> tt;
      for(auto x : T[i]){
        if(did[x] != -1){
          if(sal[i] > sal[x])
            tt.push_back(did[x]);
        }
      }
      sort(tt.begin(), tt.end());
      for(auto x : tt){
        add(x, -(deg[i]-b[i])*1ll*b[i]);
        b[i] -- ;
        add(x, (deg[i]-b[i])*1ll*b[i]);
      }
    }
    for(int i = 0 ; i < ask.size(); i ++ ){
      add(i, -(deg[ask[i]]-b[ask[i]])*1ll*b[ask[i]]);
      b[ask[i]] = deg[ask[i]];
      for(auto x : R[ask[i]]){
        if(sal[ask[i]] < sal[x]){
          add(i, -(deg[x]-b[x])*1ll*b[x]);
          b[x] -- ;
          add(i, (deg[x]-b[x])*1ll*b[x]);
        }
      }
      sal[ask[i]] = n + l + i + 1;
    }

    for(int i = l ; i <= r; i ++ ){
      res += f[i];
      cout << res << "\n";
    }
    l += B;
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)1e5 + 1;
const int B = 300;
vector<int> T[N];
vector<int> R[N];
int deg[N];
int b[N];
int u[N], v[N];

vector<int> ask;
int did[N];

ll f[B + 55];

void add(int li, ll di){
  f[li] += di;
}

int sal[N];

int main(){
  fastIO;
  int n, m;
  cin >> n >> m;
  for(int i = 0 ;i  <m ; i ++ ){
    cin >> u[i] >> v[i];
    deg[u[i]] ++ ;
    deg[v[i]] ++ ;
    if(u[i] > v[i]) swap(u[i], v[i]);
      b[v[i]] ++ ;
    T[u[i]].push_back(v[i]);
    T[v[i]].push_back(u[i]);
  }
  ll res = 0;
  for(int i = 1; i <= n; i ++ ){
    res += (deg[i] - b[i]) * 1ll * b[i];
    sal[i] = i;
  }
  cout << res << "\n";
  int q;
  cin >> q;
  int l=0,r;
  int v;
  while(l < q){
    r = min(q-1, l+B-1);
    for(int i = 0 ;i <= B;i ++ )
      f[i] = 0;
    ask.clear();
    for(int i = 1; i <= n; i ++ ){
      did[i] = -1;
      R[i].clear();
    }
    for(int t = l; t <= r; t ++ ){
      cin >> v;
      ask.push_back(v);
    }
    for(int i = (int)ask.size() - 1; i >= 0 ; i -- ){
      did[ask[i]] = i;
    }
    for(int i = 1; i <= n; i ++ ){
      if(did[i] != -1){
        for(auto x : T[i]){
          if(did[x] != -1){
            R[i].push_back(x);
          }
        }
      }
    }
    for(int i = 1; i <= n; i ++ ){
      if(did[i] != -1) continue;
      vector<int> tt;
      for(auto x : T[i]){
        if(did[x] != -1){
          if(sal[i] > sal[x])
            tt.push_back(did[x]);
        }
      }
      sort(tt.begin(), tt.end());
      for(auto x : tt){
        add(x, -(deg[i]-b[i])*1ll*b[i]);
        b[i] -- ;
        add(x, (deg[i]-b[i])*1ll*b[i]);
      }
    }

    for(int i = 0 ; i < 2; i ++ ){
      add(i, -(deg[ask[i]]-b[ask[i]])*1ll*b[ask[i]]);
      b[ask[i]] = deg[ask[i]];
      for(auto x : R[ask[i]]){
        if(sal[ask[i]] > sal[x]){
          add(i, -(deg[x]-b[x])*1ll*b[x]);
          b[x] -- ;
          add(i, (deg[x]-b[x])*1ll*b[x]);
        }
      }
      sal[i] = n + l + i + 1;
    }

    for(int i = l ; i <= r; i ++ ){
      res += f[i];
      cout << res << "\n";
    }
    l += B;
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)1e5 + 1;
const int B = 300;
vector<int> T[N];
vector<int> R[N];
ll deg[N];
ll b[N];
ll u[N], v[N];

vector<ll> ask;
ll did[N];

ll f[B + 55];

void add(int li, ll di){
  f[li] += di;
}

ll sal[N];

int main(){
  fastIO;
  ll n, m;
  cin >> n >> m;
  for(int i = 0 ;i  <m ; i ++ ){
    cin >> u[i] >> v[i];
    deg[u[i]] ++ ;
    deg[v[i]] ++ ;
    if(u[i] > v[i]) swap(u[i], v[i]);
      b[v[i]] ++ ;
    T[u[i]].push_back(v[i]);
    T[v[i]].push_back(u[i]);
  }
  ll res = 0;
  for(int i = 1; i <= n; i ++ ){
    res += (deg[i] - b[i]) * 1ll * b[i];
    sal[i] = i;
  }
  cout << res << "\n";
  int q;
  cin >> q;
  int l=0,r;
  int v;
  while(l < q){
    r = min(q-1, l+B-1);
    for(int i = 0 ;i <= B;i ++ )
      f[i] = 0;
    ask.clear();
    for(int i = 1; i <= n; i ++ ){
      did[i] = -1;
      R[i].clear();
    }
    for(int t = l; t <= r; t ++ ){
      cin >> v;
      ask.push_back(v);
    }
    for(int i = (int)ask.size() - 1; i >= 0 ; i -- ){
      did[ask[i]] = i;
    }
    for(int i = 1; i <= n; i ++ ){
      if(did[i] != -1){
        for(auto x : T[i]){
          if(did[x] != -1){
            R[i].push_back(x);
          }
        }
      }
    }
    for(int i = 1; i <= n; i ++ ){
      if(did[i] != -1) continue;
      vector<int> tt;
      for(auto x : T[i]){
        if(did[x] != -1){
          if(sal[i] > sal[x])
            tt.push_back(did[x]);
        }
      }
      sort(tt.begin(), tt.end());
      for(auto x : tt){
        add(x, -(deg[i]-b[i])*1ll*b[i]);
        b[i] -- ;
        add(x, (deg[i]-b[i])*1ll*b[i]);
      }
    }
    for(int i = 0 ; i < ask.size(); i ++ ){
      add(i, -(deg[ask[i]]-b[ask[i]])*1ll*b[ask[i]]);
      b[ask[i]] = deg[ask[i]];
      for(auto x : R[ask[i]]){
        if(sal[ask[i]] < sal[x]){
          add(i, -(deg[x]-b[x])*1ll*b[x]);
          b[x] -- ;
          add(i, (deg[x]-b[x])*1ll*b[x]);
        }
      }
      sal[ask[i]] = n + l + i + 1;
    }

    for(int i = l ; i <= r; i ++ ){
      res += f[i-l];
      cout << res << "\n";
    }
    l += B;
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)1e5 + 1;
const int B = 300;
vector<int> T[N];
vector<int> R[N];
int deg[N];
int b[N];
int u[N], v[N];

vector<int> ask;
int did[N];

ll f[B + 55];

void add(int li, ll di){
  f[li] += di;
}

int sal[N];

int main(){
  fastIO;
  int n, m;
  cin >> n >> m;
  for(int i = 0 ;i  <m ; i ++ ){
    cin >> u[i] >> v[i];
    deg[u[i]] ++ ;
    deg[v[i]] ++ ;
    if(u[i] > v[i]) swap(u[i], v[i]);
      b[v[i]] ++ ;
    T[u[i]].push_back(v[i]);
    T[v[i]].push_back(u[i]);
  }
  ll res = 0;
  for(int i = 1; i <= n; i ++ ){
    res += (deg[i] - b[i]) * 1ll * b[i];
    sal[i] = i;
  }
  cout << res << "\n";
  int q;
  cin >> q;
  int l=0,r;
  int v;
  while(l < q){
    r = min(q-1, l+B-1);
    for(int i = 0 ;i <= B;i ++ )
      f[i] = 0;
    ask.clear();
    for(int i = 1; i <= n; i ++ ){
      did[i] = -1;
      R[i].clear();
    }
    for(int t = l; t <= r; t ++ ){
      cin >> v;
      ask.push_back(v);
    }
    for(int i = (int)ask.size() - 1; i >= 0 ; i -- ){
      did[ask[i]] = i;
    }
    for(int i = 1; i <= n; i ++ ){
      if(did[i] != -1){
        for(auto x : T[i]){
          if(did[x] != -1){
            R[i].push_back(x);
          }
        }
      }
    }
    for(int i = 1; i <= n; i ++ ){
      if(did[i] != -1) continue;
      vector<int> tt;
      for(auto x : T[i]){
        if(did[x] != -1){
          if(sal[i] > sal[x])
            tt.push_back(did[x]);
        }
      }
      sort(tt.begin(), tt.end());
      for(auto x : tt){
        add(x, -(deg[i]-b[i])*1ll*b[i]);
        b[i] -- ;
        add(x, (deg[i]-b[i])*1ll*b[i]);
      }
    }
    for(int i = 0 ; i < 2; i ++ ){
      add(i, -(deg[ask[i]]-b[ask[i]])*1ll*b[ask[i]]);
      b[ask[i]] = deg[ask[i]];
      for(auto x : R[ask[i]]){
        if(sal[ask[i]] < sal[x]){
          add(i, -(deg[x]-b[x])*1ll*b[x]);
          b[x] -- ;
          add(i, (deg[x]-b[x])*1ll*b[x]);
        }
      }
      sal[ask[i]] = n + l + i + 1;
    }

    for(int i = l ; i <= r; i ++ ){
      res += f[i];
      cout << res << "\n";
    }
    l += B;
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)1e5 + 1;
const int B = 300;
vector<int> T[N];
vector<int> R[N];
int deg[N];
int b[N];
int u[N], v[N];

vector<int> ask;
int did[N];

ll f[B + 55];

void add(int li, ll di){
  f[li] += di;
}

int sal[N];

int main(){
  fastIO;
  int n, m;
  cin >> n >> m;
  for(int i = 0 ;i  <m ; i ++ ){
    cin >> u[i] >> v[i];
    deg[u[i]] ++ ;
    deg[v[i]] ++ ;
    if(u[i] > v[i]) swap(u[i], v[i]);
      b[v[i]] ++ ;
    T[u[i]].push_back(v[i]);
    T[v[i]].push_back(u[i]);
  }
  ll res = 0;
  for(int i = 1; i <= n; i ++ ){
    res += (deg[i] - b[i]) * 1ll * b[i];
    sal[i] = i;
  }
  cout << res << "\n";
  int q;
  cin >> q;
  int l=0,r;
  int v;
  while(l < q){
    r = min(q-1, l+B-1);
    for(int i = 0 ;i <= B;i ++ )
      f[i] = 0;
    ask.clear();
    for(int i = 1; i <= n; i ++ ){
      did[i] = -1;
      R[i].clear();
    }
    for(int t = l; t <= r; t ++ ){
      cin >> v;
      ask.push_back(v);
    }
    for(int i = (int)ask.size() - 1; i >= 0 ; i -- ){
      did[ask[i]] = i;
    }
    for(int i = 1; i <= n; i ++ ){
      if(did[i] != -1){
        for(auto x : T[i]){
          if(did[x] != -1){
            R[i].push_back(x);
          }
        }
      }
    }
    for(int i = 1; i <= n; i ++ ){
      if(did[i] != -1) continue;
      vector<int> tt;
      for(auto x : T[i]){
        if(did[x] != -1){
          if(sal[i] > sal[x])
            tt.push_back(did[x]);
        }
      }
      sort(tt.begin(), tt.end());
      for(auto x : tt){
        add(x, -(deg[i]-b[i])*1ll*b[i]);
        b[i] -- ;
        add(x, (deg[i]-b[i])*1ll*b[i]);
      }
    }
    for(int i = 0 ; i < ask.size(); i ++ ){
      add(i, -(deg[ask[i]]-b[ask[i]])*1ll*b[ask[i]]);
      b[ask[i]] = deg[ask[i]];
      for(auto x : R[ask[i]]){
        if(sal[ask[i]] < sal[x]){
          add(i, -(deg[x]-b[x])*1ll*b[x]);
          b[x] -- ;
          add(i, (deg[x]-b[x])*1ll*b[x]);
        }
      }
      sal[ask[i]] = n + l + i + 1;
    }

    for(int i = l ; i <= r; i ++ ){
      res += f[i];
      cout << res << "\n";
    }
    l += B;
  }
  return 0;
}


#include<bits/stdc++.h>

#define pb push_back
#define x first
#define y second
using namespace std;
typedef long long INT;
typedef pair<int, int> pii;
typedef vector<int> VI;
int power(int a, int b, int m, int ans=1) {
	for(; b; b>>=1, a=1LL*a*a%m) if(b&1) ans=1LL*ans*a%m;
	return ans;
}

const int NN = 200011;
int n, m;
VI adj[NN];
int deg[NN];
int in[NN], out[NN];

int solve() {
    cin >> n >> m;
    for(int i=0; i<m; i++) {
        int u, v;
        scanf("%d %d", &u, &v);
        if(u>v) swap(u, v);
        adj[u].pb(v);
        deg[u]++; deg[v]++;
        out[u]++; in[v]++;
    }
    INT ans = 0;
    for(int i=1; i<=n; i++) ans += (INT)in[i] * out[i];
    int q;
    cin >> q;
    cout << ans << endl;
    for(int i=1; i<=q; i++) {
        int u; scanf("%d", &u);
        for(int v : adj[u]) {
            ans += in[v] - out[v] - 1;
            in[v]--; out[v]++;
            adj[v].pb(u);
        }
        adj[u].clear();
        ans -= (INT)in[u] * out[u];
        in[u]=deg[u];
        out[u]=0;
        printf("%lld\n", ans);
    }

}

int main() {
#ifndef	ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
    solve();
	return 0;
}


#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
using namespace std;
using DO = double;
using LL = long long;
using VI = vector<int>;
using pii = pair<int, int>;
const int N = 1e5+10;
set<int> ind[N];
int indeg[N], outdeg[N];
int deg[N];

int main() {
#ifndef ONLINE_JUDGE
  freopen("C.in", "r", stdin);
  freopen("out.out", "w", stdout);
#endif
  int n, m;
  scanf("%d %d", &n, &m);
  for(int i=0, u, v; i<m; i++) {
    scanf("%d %d", &u, &v);
    if(u>v) swap(u, v);
    outdeg[v]++;
    indeg[u]++;
    ind[u].insert(v);
    deg[u]++;
    deg[v]++;
  }
  LL ans=0;
  for(int i=1; i<=n; i++) {
    ans+=(LL)indeg[i]*outdeg[i];
  }
  printf("%I64d\n", ans);
  int q;
  scanf("%d", &q);
  for(int u; q--;) {
    scanf("%d", &u);
    for(auto v:ind[u]) {
      ind[v].insert(u);
      ans-=(LL)indeg[v]*outdeg[v];
      indeg[v]++; outdeg[v]--;
      ans+=(LL)indeg[v]*outdeg[v];
    }
    ans-=(LL)indeg[u]*outdeg[u];
    indeg[u]=0;
    outdeg[u]=deg[u];
    ind[u].clear();
    printf("%I64d\n", ans);
  }
  return 0;
}


#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
using namespace std;
using DO = double;
using LL = long long;
using VI = vector<int>;
using pii = pair<int, int>;
const int N = 1e5+10, M = 1e7;
int indeg[N], outdeg[N];
int deg[N];
VI adj[N];
int main() {
#ifndef ONLINE_JUDGE
  freopen("C.in", "r", stdin);
  freopen("out.out", "w", stdout);
#endif
  int n, m;
  scanf("%d %d", &n, &m);
  for(int i=0, u, v; i<m; i++) {
    scanf("%d %d", &u, &v);
    if(u>v) swap(u, v);
    outdeg[v]++;
    indeg[u]++;
    adj[u].pb(v);
    deg[u]++;
    deg[v]++;
  }
  LL ans=0;
  for(int i=1; i<=n; i++) {
    ans+=(LL)indeg[i]*outdeg[i];
  }
  printf("%I64d\n", ans);
  int q;
  scanf("%d", &q);
  for(int u; q--;) {
    scanf("%d", &u);
    for(auto v:adj[u]) {
      adj[v].pb(u);
      ans+=outdeg[v]-indeg[v]-1;
      indeg[v]++; outdeg[v]--;
    }
    ans-=(LL)indeg[u]*outdeg[u];
    indeg[u]=0;
    outdeg[u]=deg[u];
    adj[u].clear();
    printf("%I64d\n", ans);
  }
  return 0;
}


#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
using namespace std;
using DO = double;
using LL = long long;
using VI = vector<int>;
using pii = pair<int, int>;
const int N = 1e5+10;
//unordered_set<int> ind[N];
int indeg[N], outdeg[N];
int deg[N];
int head[N], nxt[N<<1], to[N<<1], E;
inline void add(int u, int v) {
  nxt[E]=head[u];
  to[E]=v;
  head[u]=E++;
}
int main() {
#ifndef ONLINE_JUDGE
  freopen("C.in", "r", stdin);
  freopen("out.out", "w", stdout);
#endif
  memset(head, -1, sizeof head);
  int n, m;
  scanf("%d %d", &n, &m);
  for(int i=0, u, v; i<m; i++) {
    scanf("%d %d", &u, &v);
    if(u>v) swap(u, v);
    outdeg[v]++;
    indeg[u]++;
//    ind[u].insert(v);
    add(u, v);
    deg[u]++;
    deg[v]++;
  }
  LL ans=0;
  for(int i=1; i<=n; i++) {
    ans+=(LL)indeg[i]*outdeg[i];
  }
  printf("%I64d\n", ans);
  int q;
  scanf("%d", &q);
  for(int u; q--;) {
    scanf("%d", &u);
//    for(auto v:ind[u]) {
    for(int e=head[u], v; ~e; e=nxt[e]) {
      v=to[e];
//      ind[v].insert(u);
      add(v, u);
      ans+=outdeg[v]-indeg[v]-1;
      indeg[v]++; outdeg[v]--;
    }
    ans-=(LL)indeg[u]*outdeg[u];
    indeg[u]=0;
    outdeg[u]=deg[u];
//    ind[u].clear();
    head[u]=-1;
    printf("%I64d\n", ans);
  }
  return 0;
}


#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
using namespace std;
using DO = double;
using LL = long long;
using VI = vector<int>;
using pii = pair<int, int>;
const int N = 1e5+10, M = 1e7;
int indeg[N], outdeg[N];
int deg[N];
int head[N], nxt[M], to[M], E;
inline void add(int u, int v) {
  nxt[E]=head[u];
  to[E]=v;
  head[u]=E++;
}
int main() {
#ifndef ONLINE_JUDGE
  freopen("C.in", "r", stdin);
  freopen("out.out", "w", stdout);
#endif
  memset(head, -1, sizeof head);
  int n, m;
  scanf("%d %d", &n, &m);
  for(int i=0, u, v; i<m; i++) {
    scanf("%d %d", &u, &v);
    if(u>v) swap(u, v);
    outdeg[v]++;
    indeg[u]++;
    add(u, v);
    deg[u]++;
    deg[v]++;
  }
  LL ans=0;
  for(int i=1; i<=n; i++) {
    ans+=(LL)indeg[i]*outdeg[i];
  }
  printf("%I64d\n", ans);
  int q;
  scanf("%d", &q);
  for(int u; q--;) {
    scanf("%d", &u);
    for(int e=head[u], v; ~e; e=nxt[e]) {
      v=to[e];
      add(v, u);
      ans+=outdeg[v]-indeg[v]-1;
      indeg[v]++; outdeg[v]--;
    }
    ans-=(LL)indeg[u]*outdeg[u];
    indeg[u]=0;
    outdeg[u]=deg[u];
    head[u]=-1;
    printf("%I64d\n", ans);
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n, m, q, ca[100005], cb[100005];
long long ans[100005];
bool cur[100005];
vector<int> v[100005], b[100005];
vector<pair<int, int>> vv[100005];

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++) {
		int ta, tb;
		scanf("%d%d", &ta, &tb);
		b[ta].push_back(tb);
		cb[ta]++;
		ca[tb]++;
	}
	scanf("%d", &q);
	for (int i = 1; i <= q; i++) {
		int tmp;
		scanf("%d", &tmp);
		vv[tmp].emplace_back(i, -b[tmp].size());
		for (int j : b[tmp]) {
			vv[j].emplace_back(i, 1);
			b[j].push_back(tmp);
		}
		b[tmp].clear();
	}
	for (int i = 1; i <= n; i++) {
		long long ta = ca[i], tb = cb[i];
		ans[0] += ta * tb;
		long long na = ta, nb = tb;
		for (int j = 0; j < vv[i].size(); j++) {
			nb += vv[i][j].second;
			na -= vv[i][j].second;
			ans[vv[i][j].first] += na * nb - ta * tb;
			ta = na;
			tb = nb;
		}
	}
	for (int i = 0; i <= q; i++) {
		printf("%lld\n", ans[i]);
		ans[i + 1] += ans[i];
	}
}


#include <bits/stdc++.h>

using namespace std;

int n, m, q;
long long ans[100005], ca[100005];
vector<int> b[100005];

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++) {
		int ta, tb;
		scanf("%d%d", &ta, &tb);
		if (ta > tb)
			swap(ta, tb);
		b[ta].push_back(tb);
		ca[tb]++;
	}
	for (int i = 1; i <= n; i++)
		ans[0] += ca[i] * (long long)b[i].size();
	scanf("%d", &q);
	for (int i = 1; i <= q; i++) {
		int tmp;
		scanf("%d", &tmp);
		ans[i] -= ca[tmp] * (long long)b[tmp].size();
		for (int j : b[tmp]) {
			ans[i] += ca[j] - (long long)b[j].size() - 1;
			ca[j]--;
			b[j].push_back(tmp);
		}
		ca[tmp] += b[tmp].size();
		b[tmp].clear();
	}
	for (int i = 0; i <= q; i++) {
		printf("%lld\n", ans[i]);
		ans[i + 1] += ans[i];
	}
}