← Home
```go
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 1024*1024), 10*1024*1024)
	scanner.Split(bufio.ScanWords)

	var nextInt = func() int {
		scanner.Scan()
		i, _ := strconv.Atoi(scanner.Text())
		return i
	}

	if !scanner.Scan() {
		return
	}
	n, _ := strconv.Atoi(scanner.Text())
	m := nextInt()

	p := make([]int, n+1)
	for i := 1; i <= n; i++ {
		p[i] = nextInt()
	}

	c := make([]int, n+1)
	for i := 1; i <= n; i++ {
		c[i] = nextInt()
	}

	d := nextInt()
	k := make([]int, d+1)
	removed := make([]bool, n+1)
	for i := 1; i <= d; i++ {
		k[i] = nextInt()
		removed[k[i]] = true
	}

	edges := make([][]int, 5005)
	count := make([]int16, 5005*5005)

	for i := 1; i <= n; i++ {
		if !removed[i] {
			pot := p[i]
			club := c[i]
			idxCount := pot*5005 + club
			if count[idxCount] == 0 {
				edges[pot] = append(edges[pot], club)
			}
			count[idxCount]++
		}
	}

	match := make([]int, m+1)
	for i := 1; i <= m; i++ {
		match[i] = -1
	}

	visited := make([]bool, m+1)
	var dfs func(int) bool
	dfs = func(u int) bool {
		for _, v := range edges[u] {
			if visited[v] {
				continue
			}
			visited[v] = true
			if match[v] == -1 || dfs(match[v]) {
				match[v] = u
				return true
			}
		}
		return false
	}

	mex := 0
	for {
		for i := 1; i <= m; i++ {
			visited[i] = false
		}
		if dfs(mex) {
			mex++
		} else {
			break
		}
	}

	ans := make([]int, d+1)
	ans[d] = mex

	for j := d; j >= 2; j-- {
		idx := k[j]
		pot := p[idx]
		club := c[idx]
		idxCount := pot*5005 + club
		if count[idxCount] == 0 {
			edges[pot] = append(edges[pot], club)
		}
		count[idxCount]++

		for {
			for i := 1; i <= m; i++ {
				visited[i] = false
			}
			if dfs(mex) {
				mex++
			} else {
				break
			}
		}
		ans[j-1] = mex
	}

	out := bufio.NewWriter(os.Stdout)
	for i := 1; i <= d; i++ {
		fmt.Fprintln(out, ans[i])
	}
	out.Flush()
}
```