There are $n$ students and $m$ clubs in a college. The clubs are numbered from $1$ to $m$. Each student has a potential $p_i$ and is a member of the club with index $c_i$. Initially, each student is a member of exactly one club. A technical fest starts in the college, and it will run for the next $d$ days. There is a coding competition every day in the technical fest. 

Every day, in the morning, exactly one student of the college leaves their club. Once a student leaves their club, they will never join any club again. Every day, in the afternoon, the director of the college will select one student from each club (in case some club has no members, nobody is selected from that club) to form a team for this day's coding competition. The strength of a team is the mex of potentials of the students in the team. The director wants to know the maximum possible strength of the team for each of the coming $d$ days. Thus, every day the director chooses such team, that the team strength is maximized.

The mex of the multiset $S$ is the smallest non-negative integer that is not present in $S$. For example, the mex of the $\{0, 1, 1, 2, 4, 5, 9\}$ is $3$, the mex of $\{1, 2, 3\}$ is $0$ and the mex of $\varnothing$ (empty set) is $0$.


-----Input-----

The first line contains two integers $n$ and $m$ ($1 \leq m \leq n \leq 5000$), the number of students and the number of clubs in college.

The second line contains $n$ integers $p_1, p_2, \ldots, p_n$ ($0 \leq p_i < 5000$), where $p_i$ is the potential of the $i$-th student.

The third line contains $n$ integers $c_1, c_2, \ldots, c_n$ ($1 \leq c_i \leq m$), which means that $i$-th student is initially a member of the club with index $c_i$.

The fourth line contains an integer $d$ ($1 \leq d \leq n$), number of days for which the director wants to know the maximum possible strength of the team. 

Each of the next $d$ lines contains an integer $k_i$ ($1 \leq k_i \leq n$), which means that $k_i$-th student lefts their club on the $i$-th day. It is guaranteed, that the $k_i$-th student has not left their club earlier.


-----Output-----

For each of the $d$ days, print the maximum possible strength of the team on that day.


-----Examples-----
Input
5 3
0 1 2 2 0
1 2 2 3 2
5
3
2
4
5
1

Output
3
1
1
1
0

Input
5 3
0 1 2 2 1
1 3 2 3 2
5
4
2
3
5
1

Output
3
2
2
1
0

Input
5 5
0 1 2 4 5
1 2 3 4 5
4
2
3
5
4

Output
1
1
1
1



-----Note-----

Consider the first example:

On the first day, student $3$ leaves their club. Now, the remaining students are $1$, $2$, $4$ and $5$. We can select students $1$, $2$ and $4$ to get maximum possible strength, which is $3$. Note, that we can't select students $1$, $2$ and $5$, as students $2$ and $5$ belong to the same club. Also, we can't select students $1$, $3$ and $4$, since student $3$ has left their club.

On the second day, student $2$ leaves their club. Now, the remaining students are $1$, $4$ and $5$. We can select students $1$, $4$ and $5$ to get maximum possible strength, which is $1$.

On the third day, the remaining students are $1$ and $5$. We can select students $1$ and $5$ to get maximum possible strength, which is $1$.

On the fourth day, the remaining student is $1$. We can select student $1$ to get maximum possible strength, which is $1$. 

On the fifth day, no club has students and so the maximum possible strength is $0$.

Source: codeforces | Difficulty: VERY_HARD
Tags: Graph algorithms

Flows and cuts


Solutions:
(n, m) = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
d = int(input())
k = []
for i in range(d):
	k.append(int(input()))
vis = [False for i in range(m + 1)]
match = [-1 for i in range(m + 1)]

def dfs(u: int) -> bool:
	for v in e[u]:
		if not vis[v]:
			vis[v] = True
			if match[v] == -1 or dfs(match[v]):
				match[v] = u
				return True
	return False
e = [[] for i in range(5005)]
for i in range(n):
	if i + 1 not in k:
		e[p[i]].append(c[i])
mex = 0
ans = []
for i in range(d - 1, -1, -1):
	while True:
		vis = [False for j in range(m + 1)]
		if not dfs(mex):
			break
		mex += 1
	ans.append(mex)
	e[p[k[i] - 1]].append(c[k[i] - 1])
for i in reversed(ans):
	print(i)


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
d = int(input())
disable = [False] * n
base = 5001
ds = [int(input()) - 1 for _ in range(d)]
for ele in ds:
	disable[ele] = True
childs = [[] for i in range(base + m + 1)]
for (idx, (i, j)) in enumerate(zip(p, c)):
	if not disable[idx]:
		childs[i].append(base + j)
vis = [False] * (base + m + 1)
matching = [-1] * (base + m + 1)

def dfs(num):
	for child in childs[num]:
		if not vis[child]:
			vis[child] = True
			if matching[child] == -1 or dfs(matching[child]):
				matching[child] = num
				return True
	return False
ans = []
mex = 0
for idx in range(d - 1, -1, -1):
	while True:
		vis = [False] * (base + m + 1)
		if not dfs(mex):
			break
		mex += 1
	ans.append(mex)
	childs[p[ds[idx]]].append(base + c[ds[idx]])
print('\n'.join([str(a) for a in reversed(ans)]))