human
Solve in Python:
There are N infants registered in AtCoder, numbered 1 to N, and 2\times 10^5 kindergartens, numbered 1 to 2\times 10^5.
Infant i has a rating of A_i and initially belongs to Kindergarten B_i.
From now on, Q transfers will happen.
After the j-th transfer, Infant C_j will belong to Kindergarten D_j.
Here, we define the evenness as follows. For each kindergarten with one or more infants registered in AtCoder, let us find the highest rating of an infant in the kindergarten. The evenness is then defined as the lowest among those ratings.
For each of the Q transfers, find the evenness just after the transfer.

-----Constraints-----
 - 1 \leq N,Q \leq 2 \times 10^5
 - 1 \leq A_i \leq 10^9
 - 1 \leq C_j \leq N
 - 1 \leq B_i,D_j \leq 2 \times 10^5
 - All values in input are integers.
 - In the j-th transfer, Infant C_j changes the kindergarten it belongs to.

-----Input-----
Input is given from Standard Input in the following format:
N Q
A_1 B_1
A_2 B_2
:
A_N B_N
C_1 D_1
C_2 D_2
:
C_Q D_Q

-----Output-----
Print Q lines.
The j-th line should contain the evenness just after the j-th transfer.

-----Sample Input-----
6 3
8 1
6 2
9 3
1 1
2 2
1 3
4 3
2 1
1 2

-----Sample Output-----
6
2
6

Initially, Infant 1, 4 belongs to Kindergarten 1, Infant 2, 5 belongs to Kindergarten 2, and Infant 3, 6 belongs to Kindergarten 3.
After the 1-st transfer that makes Infant 4 belong to Kindergarten 3, Infant 1 belongs to Kindergarten 1, Infant 2, 5 belong to Kindergarten 2, and Infant 3, 4, 6 belong to Kindergarten 3. The highest ratings of an infant in Kindergarten 1, 2, 3 are 8, 6, 9, respectively. The lowest among them is 6, so the 1-st line in the output should contain 6.
After the 2-nd transfer that makes Infant 2 belong to Kindergarten 1, Infant 1, 2 belong to Kindergarten 1, Infant 5 belongs to Kindergarten 2, and Infant 3, 4, 6 belong to Kindergarten 3. The highest ratings of an infant in Kindergarten 1, 2, 3 are 8, 2, 9, respectively. The lowest among them is 2, so the 2-nd line in the output should contain 2.
After the 3-rd...

What is a Python code to find the highest rating of an infant in the kindergarten?
assistant
#Here is Python code to find the highest rating of an infant in the kindergarten.

import heapq

class HeapDict:
    def __init__(self):
        # heapqとdictを用意
        self.h = []
        self.d = dict()

    def insert(self, x):
        heapq.heappush(self.h, x)
        if x not in self.d:
            self.d[x] = 1
        else:
            self.d[x] += 1

    def erase(self, x):
        if x not in self.d or self.d[x] == 0:
            print((x, "is not in HeapDict"))
            return
        else:
            self.d[x] -= 1

        while len(self.h) != 0:
            if self.d[self.h[0]] == 0:
                heapq.heappop(self.h)
            else:
                break

    def is_exist(self, x):
        if x in self.d and self.d[x] != 0:
            return True
        else:
            False

    def get_min(self):
        return self.h[0]

    def size(self):
        return len(self.h)

def main():
    N, Q = list(map(int, input().split()))
    A = []  # レート
    B = []  # 所属幼稚園
    con = 2 * 10 ** 5
    INF = 10 ** 18
    youchi = [HeapDict() for _ in range(con)]  # 各幼稚園に対するHeapDict
    max_values = HeapDict()  # 各幼稚園の最大値のHeapDict
    for i in range(N):
        a, b = list(map(int, input().split()))
        b -= 1
        A.append(a)
        B.append(b)
        youchi[b].insert(-a)

    for i in range(con):  # 各幼稚園の最大値をまとめる
        if youchi[i].size() != 0:
            max_values.insert(-youchi[i].get_min())
        else:
            max_values.insert(INF)

    for i in range(Q):
        c, d = list(map(int, input().split()))
        c -= 1
        d -= 1
        rate = A[c]
        youchi_now = B[c]
        youchi_next = d

        # 最強園児のレートの集合から、転園する園児の元の幼稚園の元の最強園児のレートを、削除する
        max_values.erase(-youchi[youchi_now].get_min())

        # 転園する園児の元の幼稚園のレートの集合から、転園する園児のレートを、削除する
        youchi[youchi_now].erase(-rate)

        # 最強園児のレートの集合に、転園する園児の元の幼稚園の新しい最強園児のレートを、挿入する(園児が一人もいない場合何もしない)
        if youchi[youchi_now].size() != 0:
            max_values.insert(-youchi[youchi_now].get_min())

        # 最強園児のレートの集合から、転園する園児の新しい幼稚園の元の最強園児のレートを、削除する(園児が一人もいない場合何もしない)
        if...