Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
B = [list(map(int, input().split())) for _ in range(M)]

pt = []
G = [0 for x in range(N+1)]
C = [1 for x in range(N+1)]

def find(x):
    while G[x] != 0:
        x = G[x]
    return x

cnt = 0
while len(B):
    x, y = B.pop()
    wx = find(x)
    wy = find(y)
    if wx is wy:
        pt.append(0)
    else:
        pt.append(C[wx] * C[wy])
        C[wx] += C[wy]
        G[wy] = wx

    #print(G)

cnt = 0
for _ in range(M):
    cnt += pt.pop()
    print(cnt)


Fixed submission:
N, M = map(int, input().split())
B = [list(map(int, input().split())) for _ in range(M)]

pt = []
G = [[None, 1] for x in range(N+1)]

def find(x):
    n = G[x]
    c = []
    while not n[0] is None:
        c.append(n)
        n = n[0]
    for ci in c:
        ci[0] = n
    return n

cnt = 0
while len(B):
    x, y = B.pop()
    wx = find(x)
    wy = find(y)
    if wx is wy:
        pt.append(0)
    else:
        pt.append(wx[1] * wy[1])
        wx[1] += wy[1]
        wy[0] = wx

    #print(G)

cnt = 0
for _ in range(M):
    cnt += pt.pop()
    print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
B = [list(map(int, input().split())) for _ in range(M)]

pt = []
G = [0 for x in range(N+1)]
C = [1 for x in range(N+1)]

def find(x):
    while G[x] != 0:
        x = G[x]
    return x

cnt = 0
while len(B):
    x, y = B.pop()
    wx = find(x)
    wy = find(y)
    if wx is wy:
        pt.append(0)
    else:
        pt.append(C[wx] * C[wy])
        C[wx] += C[wy]
        G[wy] = wx

    #print(G)

cnt = 0
while len(pt):
    cnt += pt.pop()
    print(cnt)


Fixed submission:
N, M = map(int, input().split())
B = [list(map(int, input().split())) for _ in range(M)]

pt = []
G = [[None, 1] for x in range(N+1)]

def find(x):
    n = G[x]
    c = []
    while not n[0] is None:
        c.append(n)
        n = n[0]
    for ci in c:
        ci[0] = n
    return n

cnt = 0
while len(B):
    x, y = B.pop()
    wx = find(x)
    wy = find(y)
    if wx is wy:
        pt.append(0)
    else:
        pt.append(wx[1] * wy[1])
        wx[1] += wy[1]
        wy[0] = wx

    #print(G)

cnt = 0
for _ in range(M):
    cnt += pt.pop()
    print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
B = [list(map(int, input().split())) for _ in range(M)]

pt = []
G = [[0, 1] for x in range(N+1)]

def find(x):
    while G[x][0] != 0:
        x = G[x][0]
    return x

cnt = 0
while len(B):
    x, y = B.pop()
    wx = find(x)
    wy = find(y)
    if wx == wy:
        pt.append(0)
    else:
        pt.append(G[wx][1] * G[wy][1])
        G[wx][1] += G[wy][1]
        G[wy][0] = wx

    #print(G)

cnt = 0
while len(pt):
    cnt += pt.pop()
    print(cnt)


Fixed submission:
N, M = map(int, input().split())
B = [list(map(int, input().split())) for _ in range(M)]

pt = []
G = [[None, 1] for x in range(N+1)]

def find(x):
    n = G[x]
    c = []
    while not n[0] is None:
        c.append(n)
        n = n[0]
    for ci in c:
        ci[0] = n
    return n

cnt = 0
while len(B):
    x, y = B.pop()
    wx = find(x)
    wy = find(y)
    if wx is wy:
        pt.append(0)
    else:
        pt.append(wx[1] * wy[1])
        wx[1] += wy[1]
        wy[0] = wx

    #print(G)

cnt = 0
for _ in range(M):
    cnt += pt.pop()
    print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
B = [list(map(int, input().split())) for _ in range(M)]

pt = []
G = [[None, 1] for x in range(N+1)]

def find(x):
    n = G[x]
    while not n[0] is None:
        n = n[0]
    return n

cnt = 0
while len(B):
    x, y = B.pop()
    wx = find(x)
    wy = find(y)
    if wx is wy:
        pt.append(0)
    else:
        pt.append(wx[1] * wy[1])
        wx[1] += wy[1]
        wy[0] = wx

    #print(G)

cnt = 0
while len(pt):
    cnt += pt.pop()
    print(cnt)


Fixed submission:
N, M = map(int, input().split())
B = [list(map(int, input().split())) for _ in range(M)]

pt = []
G = [[None, 1] for x in range(N+1)]

def find(x):
    n = G[x]
    c = []
    while not n[0] is None:
        c.append(n)
        n = n[0]
    for ci in c:
        ci[0] = n
    return n

cnt = 0
while len(B):
    x, y = B.pop()
    wx = find(x)
    wy = find(y)
    if wx is wy:
        pt.append(0)
    else:
        pt.append(wx[1] * wy[1])
        wx[1] += wy[1]
        wy[0] = wx

    #print(G)

cnt = 0
for _ in range(M):
    cnt += pt.pop()
    print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
B = [list(map(int, input().split())) for _ in range(M)]

pt = []
G = [[None, 1] for x in range(N+1)]

def find(x):
    n = G[x]
    while not n[0] is None:
        n = n[0]
    return n

cnt = 0
while len(B):
    x, y = B.pop()
    wx = find(x)
    wy = find(y)
    if wx is wy:
        pt.append(0)
    else:
        pt.append(wx[1] * wy[1])
        wx[1] += wy[1]
        wy[0] = wx

    #print(G)

cnt = 0
while len(pt):
    cnt += pt.pop()
    print(cnt)


Fixed submission:
N, M = map(int, input().split())
B = [list(map(int, input().split())) for _ in range(M)]

pt = []
G = [[None, 1] for x in range(N+1)]

def find(x):
    n = G[x]
    c = []
    while not n[0] is None:
        c.append(n)
        n = n[0]
    for ci in c:
        ci[0] = n
    return n

cnt = 0
while len(B):
    x, y = B.pop()
    wx = find(x)
    wy = find(y)
    if wx is wy:
        pt.append(0)
    else:
        pt.append(wx[1] * wy[1])
        wx[1] += wy[1]
        wy[0] = wx

    #print(G)

cnt = 0
for _ in range(M):
    cnt += pt.pop()
    print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

B = [list(map(int, input().split())) for _ in range(M)]

class Group:
    id = 0
    def __init__(self):
        self.id = Group.id
        Group.id += 1
        self.count = 1
        self.root = None

    def top(self):
        w = self
        while not w.root is None:
            w = w.root
        return w

    def union(self, g):
        ss, gg = self.top(), g.top()
        ss.count += gg.count
        gg.root = ss

pt = []
G = [Group() for x in range(N+1)]
idx = 0
cnt = 0
while len(B):
    x, y = B.pop()
    wx = G[x].top()
    wy = G[y].top()
    if wx is wy:
        pt.append(0)
    else:
        pt.append(wx.count * wy.count)
        wx.union(wy)

    #print(G)

cnt = 0
while len(pt):
    cnt += pt.pop()
    print(cnt)


Fixed submission:
N, M = map(int, input().split())
B = [list(map(int, input().split())) for _ in range(M)]

pt = []
G = [[None, 1] for x in range(N+1)]

def find(x):
    n = G[x]
    c = []
    while not n[0] is None:
        c.append(n)
        n = n[0]
    for ci in c:
        ci[0] = n
    return n

cnt = 0
while len(B):
    x, y = B.pop()
    wx = find(x)
    wy = find(y)
    if wx is wy:
        pt.append(0)
    else:
        pt.append(wx[1] * wy[1])
        wx[1] += wy[1]
        wy[0] = wx

    #print(G)

cnt = 0
for _ in range(M):
    cnt += pt.pop()
    print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

B = [list(map(int, input().split())) for _ in range(M)]

class Group:
    id = 0
    def __init__(self):
        self.id = Group.id
        Group.id += 1
        self.count = 1
        self.root = None

    def top(self):
        w = self
        while not w.root is None:
            w = w.root
        return w

    def union(self, g):
        ss, gg = self.top(), g.top()
        ss.count += gg.count
        gg.root = ss

pt = []
G = [Group() for x in range(N+1)]
idx = 0
cnt = 0
while len(B):
    x, y = B.pop()
    wx = G[x].top()
    wy = G[y].top()
    if wx is wy:
        pt.append(0)
    else:
        pt.append(wx.count * wy.count)
        wx.union(wy)

    #print(G)

cnt = 0
while len(pt):
    cnt += pt.pop()
    print(cnt)


Fixed submission:
N, M = map(int, input().split())
B = [list(map(int, input().split())) for _ in range(M)]

pt = []
G = [[None, 1] for x in range(N+1)]

def find(x):
    n = G[x]
    c = []
    while not n[0] is None:
        c.append(n)
        n = n[0]
    for ci in c:
        ci[0] = n
    return n

cnt = 0
while len(B):
    x, y = B.pop()
    wx = find(x)
    wy = find(y)
    if wx is wy:
        pt.append(0)
    else:
        pt.append(wx[1] * wy[1])
        wx[1] += wy[1]
        wy[0] = wx

    #print(G)

cnt = 0
for _ in range(M):
    cnt += pt.pop()
    print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

B = [list(map(int, input().split())) for _ in range(M)]

class Group:
    id = 0
    def __init__(self):
        self.id = Group.id
        Group.id += 1
        self.count = 1
        self.root = None

    def top(self):
        w = self
        while not w.root is None:
            w = w.root
        return w

    def union(self, g):
        ss, gg = self.top(), g.top()
        ss.count += gg.count
        gg.root = ss.top()

pt = []
G = [Group() for x in range(N+1)]
idx = 0
cnt = 0
while len(B):
    x, y = B.pop()
    wx = G[x].top()
    wy = G[y].top()
    if wx is wy:
        pt.append(0)
    else:
        pt.append(wx.count * wy.count)
        wx.union(wy)

    #print(G)

cnt = 0
while len(pt):
    cnt += pt.pop()
    print(cnt)


Fixed submission:
N, M = map(int, input().split())
B = [list(map(int, input().split())) for _ in range(M)]

pt = []
G = [[None, 1] for x in range(N+1)]

def find(x):
    n = G[x]
    c = []
    while not n[0] is None:
        c.append(n)
        n = n[0]
    for ci in c:
        ci[0] = n
    return n

cnt = 0
while len(B):
    x, y = B.pop()
    wx = find(x)
    wy = find(y)
    if wx is wy:
        pt.append(0)
    else:
        pt.append(wx[1] * wy[1])
        wx[1] += wy[1]
        wy[0] = wx

    #print(G)

cnt = 0
for _ in range(M):
    cnt += pt.pop()
    print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

B = [list(map(int, input().split())) for _ in range(M)]

class Group:
    id = 0
    def __init__(self):
        self.id = Group.id
        Group.id += 1
        self.count = 1
        self.root = None

    def top(self):
        w = self
        while not w.root is None:
            w = w.root
        return w

    def addMember(self):
        self.count += 1

    def union(self, g):
        self.top().count += g.top().count
        g.top().root = self.top()

    def __repr__(self):
        w = self.top()
        return str(("Gropup", w.id, w.count))

pt = []
G = [Group() for x in range(N+1)]
idx = 0
cnt = 0
while len(B):
    x, y = B.pop()
    wx = G[x].top()
    wy = G[y].top()
    if wx is wy:
        pt.append(0)
    else:
        pt.append(wx.count * wy.count)
        wx.union(wy)

    #print(G)

cnt = 0
while len(pt):
    cnt += pt.pop()
    print(cnt)


Fixed submission:
N, M = map(int, input().split())
B = [list(map(int, input().split())) for _ in range(M)]

pt = []
G = [[None, 1] for x in range(N+1)]

def find(x):
    n = G[x]
    c = []
    while not n[0] is None:
        c.append(n)
        n = n[0]
    for ci in c:
        ci[0] = n
    return n

cnt = 0
while len(B):
    x, y = B.pop()
    wx = find(x)
    wy = find(y)
    if wx is wy:
        pt.append(0)
    else:
        pt.append(wx[1] * wy[1])
        wx[1] += wy[1]
        wy[0] = wx

    #print(G)

cnt = 0
for _ in range(M):
    cnt += pt.pop()
    print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

B = [list(map(int, input().split())) for _ in range(M)]

class Group:
    id = 0
    def __init__(self):
        self.id = Group.id
        Group.id += 1
        self.count = 1
        self.root = None

    def top(self):
        w = self
        while not w.root is None:
            w = w.root
        return w

    def addMember(self):
        self.count += 1

    def union(self, g):
        self.top().count += g.top().count
        g.top().root = self.top()

    def __repr__(self):
        w = self.top()
        return str(("Gropup", w.id, w.count))

pt = []
G = [Group() for x in range(N+1)]
idx = 0
cnt = 0
while len(B):
    x, y = B.pop()
    wx = G[x]
    wy = G[y]
    if wx.top() is wy.top():
        pt.append(0)
    else:
        pt.append(wx.top().count * wy.top().count)
        wx.union(wy)

    #print(G)

cnt = 0
while len(pt):
    cnt += pt.pop()
    print(cnt)


Fixed submission:
N, M = map(int, input().split())
B = [list(map(int, input().split())) for _ in range(M)]

pt = []
G = [[None, 1] for x in range(N+1)]

def find(x):
    n = G[x]
    c = []
    while not n[0] is None:
        c.append(n)
        n = n[0]
    for ci in c:
        ci[0] = n
    return n

cnt = 0
while len(B):
    x, y = B.pop()
    wx = find(x)
    wy = find(y)
    if wx is wy:
        pt.append(0)
    else:
        pt.append(wx[1] * wy[1])
        wx[1] += wy[1]
        wy[0] = wx

    #print(G)

cnt = 0
for _ in range(M):
    cnt += pt.pop()
    print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

B = [list(map(int, input().split())) for _ in range(M)][::-1]

class Group:
    id = 0
    def __init__(self):
        self.id = Group.id
        Group.id += 1
        self.root = None
        self.count = 1

    def top(self):
        w = self
        while not w.root is None:
            w = w.root
        return w

    def addMember(self):
        self.count += 1

    def union(self, g):
        self.top().count += g.top().count
        g.top().root = self.top()

    def __repr__(self):
        w = self.top()
        return str(("Gropup", w.id, w.count))

pt = []
G = [Group() for x in range(N+1)]
idx = 0
cnt = 0
for x, y in B:
    wx = G[x]
    wy = G[y]
    if wx.top() is wy.top():
        pt.append(0)
    else:
        pt.append(wx.top().count * wy.top().count)
        wx.union(wy)

    #print(G)

cnt = 0
for x in pt[::-1]:
    cnt += x
    print(cnt)


Fixed submission:
N, M = map(int, input().split())
B = [list(map(int, input().split())) for _ in range(M)]

pt = []
G = [[None, 1] for x in range(N+1)]

def find(x):
    n = G[x]
    c = []
    while not n[0] is None:
        c.append(n)
        n = n[0]
    for ci in c:
        ci[0] = n
    return n

cnt = 0
while len(B):
    x, y = B.pop()
    wx = find(x)
    wy = find(y)
    if wx is wy:
        pt.append(0)
    else:
        pt.append(wx[1] * wy[1])
        wx[1] += wy[1]
        wy[0] = wx

    #print(G)

cnt = 0
for _ in range(M):
    cnt += pt.pop()
    print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

B = [list(map(int, input().split())) for _ in range(M)][::-1]

class Group:
    id = 0
    def __init__(self):
        self.id = Group.id
        Group.id += 1
        self.root = None
        self.count = 1
        self.children = [self]

    def top(self):
        w = self
        while not w.root is None:
            w = w.root
        return w

    def addMember(self):
        self.count += 1

    def union(self, g):
        self.top().count += g.top().count
        self.top().children.extend(g.top().children)
        for x in g.top().children:
            x.root = self.top()

    def __repr__(self):
        w = self.top()
        return str(("Gropup", w.id, w.count))

pt = []
G = [Group() for x in range(N+1)]
idx = 0
cnt = 0
for x, y in B:
    wx = G[x]
    wy = G[y]
    if wx.top() is wy.top():
        pt.append(0)
    else:
        pt.append(wx.top().count * wy.top().count)
        wx.union(wy)

    #print(G)

cnt = 0
for x in pt[::-1]:
    cnt += x
    print(cnt)


Fixed submission:
N, M = map(int, input().split())
B = [list(map(int, input().split())) for _ in range(M)]

pt = []
G = [[None, 1] for x in range(N+1)]

def find(x):
    n = G[x]
    c = []
    while not n[0] is None:
        c.append(n)
        n = n[0]
    for ci in c:
        ci[0] = n
    return n

cnt = 0
while len(B):
    x, y = B.pop()
    wx = find(x)
    wy = find(y)
    if wx is wy:
        pt.append(0)
    else:
        pt.append(wx[1] * wy[1])
        wx[1] += wy[1]
        wy[0] = wx

    #print(G)

cnt = 0
for _ in range(M):
    cnt += pt.pop()
    print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

B = [list(map(int, input().split())) for _ in range(M)][::-1]

class Group:
    id = 0
    def __init__(self):
        self.id = Group.id
        Group.id += 1
        self.root = None
        self.count = 1

    def top(self):
        w = self
        while not w.root is None:
            w = w.root
        return w

    def addMember(self):
        self.count += 1

    def union(self, g):
        self.top().count += g.top().count
        g.top().root = self.top()

    def __repr__(self):
        w = self.top()
        return str(("Gropup", w.id, w.count))

pt = []
G = [Group() for x in range(N+1)]
idx = 0
cnt = 0
for x, y in B:
    wx = G[x]
    wy = G[y]
    if wx.top() is wy.top():
        pt.append(0)
    else:
        pt.append(wx.top().count * wy.top().count)
        wx.union(wy)

    #print(G)

cnt = 0
for x in pt[::-1]:
    cnt += x
    print(cnt)


Fixed submission:
N, M = map(int, input().split())
B = [list(map(int, input().split())) for _ in range(M)]

pt = []
G = [[None, 1] for x in range(N+1)]

def find(x):
    n = G[x]
    c = []
    while not n[0] is None:
        c.append(n)
        n = n[0]
    for ci in c:
        ci[0] = n
    return n

cnt = 0
while len(B):
    x, y = B.pop()
    wx = find(x)
    wy = find(y)
    if wx is wy:
        pt.append(0)
    else:
        pt.append(wx[1] * wy[1])
        wx[1] += wy[1]
        wy[0] = wx

    #print(G)

cnt = 0
for _ in range(M):
    cnt += pt.pop()
    print(cnt)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())

B = [list(map(int, input().split())) for _ in range(M)][::-1]

class Group:
    id = 0
    def __init__(self):
        self.id = Group.id
        Group.id += 1
        self.root = None
        self.children = []
        self.count = 2

    def top(self):
        w = self
        while not w.root is None:
            w = w.root
        return w

    def addMember(self):
        self.count += 1

    def union(self, g):
        self.top().count += g.top().count
        self.top().children.extend(g.top().children)
        ch = g.top().children
        for x in ch:
            x.root = self.top()
        g.top().root = self.top()

    def __repr__(self):
        w = self.top()
        return str(("Gropup", w.id, w.count))

pt = []
G = [None] * (N+1)
idx = 0
cnt = 0
for x, y in B:
    wx = G[x]
    wy = G[y]
    wcnt = (wx is None) + (wy is None)

    if wcnt >= 2:
        pt.append(1)
        w = Group()
        G[x] = w
        G[y] = w
    elif wcnt == 1:
        if wx is None:
            wx = wy
            G[x] = G[y]
        else:
            G[y] = G[x]
        pt.append(wx.top().count)
        wx.addMember()
    else:
        if wx.top() is wy.top():
            pt.append(0)
        else:
            pt.append(wx.top().count * wy.top().count)
            wx.union(wy)

    print(G)

cnt = 0
for x in pt[::-1]:
    cnt += x
    print(cnt)


Fixed submission:
N, M = map(int, input().split())
B = [list(map(int, input().split())) for _ in range(M)]

pt = []
G = [[None, 1] for x in range(N+1)]

def find(x):
    n = G[x]
    c = []
    while not n[0] is None:
        c.append(n)
        n = n[0]
    for ci in c:
        ci[0] = n
    return n

cnt = 0
while len(B):
    x, y = B.pop()
    wx = find(x)
    wy = find(y)
    if wx is wy:
        pt.append(0)
    else:
        pt.append(wx[1] * wy[1])
        wx[1] += wy[1]
        wy[0] = wx

    #print(G)

cnt = 0
for _ in range(M):
    cnt += pt.pop()
    print(cnt)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())

B = [list(map(int, input().split())) for _ in range(M)][::-1]

pt = []
G = [None] * (N+1)
C = [0] * (N+1)
idx = 0
cnt = 0
for x, y in B:
    wx = G[x]
    wy = G[y]
    wcnt = (wx is None) + (wy is None)

    if wcnt >= 2:
        pt.append(1)
        w = [idx]
        C[idx] += 2
        idx += 1
        G[x] = w
        G[y] = w
    elif wcnt == 1:
        if wx is None:
            wx = wy
            G[x] = G[y]
        else:
            G[y] = G[x]
        pt.append(C[wx[0]])
        C[wx[0]] += 1
    else:
        if wx[0] == wy[0]:
            pt.append(0)
        else:
            pt.append(C[wx[0]] * C[wy[0]])
            C[wx[0]] += C[wy[0]]
            G[y][0] = G[x][0]

    #print((G, C))

cnt = 0
for x in pt[::-1]:
    cnt += x
    print(cnt)


Fixed submission:
N, M = map(int, input().split())
B = [list(map(int, input().split())) for _ in range(M)]

pt = []
G = [[None, 1] for x in range(N+1)]

def find(x):
    n = G[x]
    c = []
    while not n[0] is None:
        c.append(n)
        n = n[0]
    for ci in c:
        ci[0] = n
    return n

cnt = 0
while len(B):
    x, y = B.pop()
    wx = find(x)
    wy = find(y)
    if wx is wy:
        pt.append(0)
    else:
        pt.append(wx[1] * wy[1])
        wx[1] += wy[1]
        wy[0] = wx

    #print(G)

cnt = 0
for _ in range(M):
    cnt += pt.pop()
    print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

B = [list(map(int, input().split())) for _ in range(M)][::-1]

S = []
pt = []
cnt = 0
for pair in B:
    d = []
    for x in pair:
        for j, s in enumerate(S):
            if x in s:
                d.append(j)

    if len(d) <= 0:
        pt.append(1)
        S.append(set(pair))
    elif len(d) == 1:
        pt.append(len(S[d[0]]))
        S[d[0]].add(pair[0])
        S[d[0]].add(pair[1])
    else:
        if d[0] == d[1]:
            pt.append(0)
        else:
            pt.append(len(S[d[0]]) * len(S[d[1]]))
            S[d[0]] = S[d[0]].union(S[d[1]])
            del S[d[1]]

cnt = 0
for x in pt[::-1]:
    cnt += x
    print(cnt)


Fixed submission:
N, M = map(int, input().split())
B = [list(map(int, input().split())) for _ in range(M)]

pt = []
G = [[None, 1] for x in range(N+1)]

def find(x):
    n = G[x]
    c = []
    while not n[0] is None:
        c.append(n)
        n = n[0]
    for ci in c:
        ci[0] = n
    return n

cnt = 0
while len(B):
    x, y = B.pop()
    wx = find(x)
    wy = find(y)
    if wx is wy:
        pt.append(0)
    else:
        pt.append(wx[1] * wy[1])
        wx[1] += wy[1]
        wy[0] = wx

    #print(G)

cnt = 0
for _ in range(M):
    cnt += pt.pop()
    print(cnt)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())

B = [list(map(int, input().split())) for _ in range(M)][::-1]

S = []
pt = []
G = [None] * (N+1)
C = [0] * (N+1)
idx = 0
cnt = 0
for pair in B:
    d = []
    for i, x in enumerate(pair):
        if not G[x] is None:
            d.append(G[x])

    if len(d) <= 0:
        pt.append(1)
        w = [idx]
        C[idx] += 2
        idx += 1
        for x in pair:
            G[x] = w
    elif len(d) == 1:
        pt.append(C[d[0][0]])
        C[d[0][0]] += 1
        for x in pair:
            if G[x] is None:
                G[x] = d[0]
    else:
        if d[0][0] == d[1][0]:
            pt.append(0)
        else:
            pt.append(C[d[0][0]] * C[d[1][0]])
            C[d[0][0]] += C[d[1][0]]
            d[1][0] = d[0][0]

    print(G)

cnt = 0
for x in pt[::-1]:
    cnt += x
    print(cnt)


Fixed submission:
N, M = map(int, input().split())
B = [list(map(int, input().split())) for _ in range(M)]

pt = []
G = [[None, 1] for x in range(N+1)]

def find(x):
    n = G[x]
    c = []
    while not n[0] is None:
        c.append(n)
        n = n[0]
    for ci in c:
        ci[0] = n
    return n

cnt = 0
while len(B):
    x, y = B.pop()
    wx = find(x)
    wy = find(y)
    if wx is wy:
        pt.append(0)
    else:
        pt.append(wx[1] * wy[1])
        wx[1] += wy[1]
        wy[0] = wx

    #print(G)

cnt = 0
for _ in range(M):
    cnt += pt.pop()
    print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

B = [list(map(int, input().split())) for _ in range(M)][::-1]

S = []
pt = []
G = [-1] * (N+1)
C = [0] * (N+1)
idx = 0
cnt = 0
for pair in B:
    d = []
    for i, x in enumerate(pair):
        if G[x] >= 0:
            d.append(G[x])

    if len(d) <= 0:
        pt.append(1)
        for x in pair:
            G[x] = idx
            C[idx] += 1
        idx += 1
    elif len(d) == 1:
        pt.append(C[d[0]])
        for x in pair:
            if G[x] < 0:
                G[x] = d[0]
                C[d[0]] += 1
    else:
        if d[0] == d[1]:
            pt.append(0)
        else:
            pt.append(C[d[0]] * C[d[1]])
            for i, x in enumerate(G):
                if x == d[1]:
                    G[i] = d[0]
                    C[d[0]] += 1
                    C[d[1]] -= 1

cnt = 0
for x in pt[::-1]:
    cnt += x
    print(cnt)


Fixed submission:
N, M = map(int, input().split())
B = [list(map(int, input().split())) for _ in range(M)]

pt = []
G = [[None, 1] for x in range(N+1)]

def find(x):
    n = G[x]
    c = []
    while not n[0] is None:
        c.append(n)
        n = n[0]
    for ci in c:
        ci[0] = n
    return n

cnt = 0
while len(B):
    x, y = B.pop()
    wx = find(x)
    wy = find(y)
    if wx is wy:
        pt.append(0)
    else:
        pt.append(wx[1] * wy[1])
        wx[1] += wy[1]
        wy[0] = wx

    #print(G)

cnt = 0
for _ in range(M):
    cnt += pt.pop()
    print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

B = [list(map(int, input().split())) for _ in range(M)][::-1]

S = []
pt = []
G = [-1] * (N+1)
C = [0] * (N+1)
idx = 0
cnt = 0
for pair in B:
    d = []
    for i, x in enumerate(pair):
        if G[x] >= 0:
            d.append(G[x])

    if len(d) <= 0:
        pt.append(1)
        for x in pair:
            G[x] = idx
            C[idx] += 1
        idx += 1
    elif len(d) == 1:
        pt.append(C[d[0]])
        for x in pair:
            if G[x] < 0:
                G[x] = d[0]
                C[d[0]] += 1
    else:
        if d[0] == d[1]:
            pt.append(0)
        else:
            pt.append(C[d[0]] * C[d[1]])
            for i, x in enumerate(G):
                if x == d[1]:
                    G[i] = d[0]
                    C[d[0]] += 1
                    C[d[1]] -= 1

cnt = 0
for x in pt[::-1]:
    cnt += x
    print(cnt)


Fixed submission:
N, M = map(int, input().split())
B = [list(map(int, input().split())) for _ in range(M)]

pt = []
G = [[None, 1] for x in range(N+1)]

def find(x):
    n = G[x]
    c = []
    while not n[0] is None:
        c.append(n)
        n = n[0]
    for ci in c:
        ci[0] = n
    return n

cnt = 0
while len(B):
    x, y = B.pop()
    wx = find(x)
    wy = find(y)
    if wx is wy:
        pt.append(0)
    else:
        pt.append(wx[1] * wy[1])
        wx[1] += wy[1]
        wy[0] = wx

    #print(G)

cnt = 0
for _ in range(M):
    cnt += pt.pop()
    print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

B = [list(map(int, input().split())) for _ in range(M)][::-1]

S = []
pt = []
G = [-1] * (N+1)
idx = 0
cnt = 0
for pair in B:
    d = []
    for i, x in enumerate(pair):
        if G[x] >= 0:
            d.append(G[x])

    if len(d) <= 0:
        pt.append(1)
        for x in pair:
            G[x] = idx
        idx += 1
    elif len(d) == 1:
        pt.append(G.count(d[0]))
        for x in pair:
            G[x] = d[0]
    else:
        if d[0] == d[1]:
            pt.append(0)
        else:
            pt.append(G.count(d[0]) * G.count(d[1]))
            for i, x in enumerate(G):
                if x == d[1]:
                    G[i] = d[0]

cnt = 0
for x in pt[::-1]:
    cnt += x
    print(cnt)


Fixed submission:
N, M = map(int, input().split())
B = [list(map(int, input().split())) for _ in range(M)]

pt = []
G = [[None, 1] for x in range(N+1)]

def find(x):
    n = G[x]
    c = []
    while not n[0] is None:
        c.append(n)
        n = n[0]
    for ci in c:
        ci[0] = n
    return n

cnt = 0
while len(B):
    x, y = B.pop()
    wx = find(x)
    wy = find(y)
    if wx is wy:
        pt.append(0)
    else:
        pt.append(wx[1] * wy[1])
        wx[1] += wy[1]
        wy[0] = wx

    #print(G)

cnt = 0
for _ in range(M):
    cnt += pt.pop()
    print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

B = [list(map(int, input().split())) for _ in range(M)][::-1]

S = []
pt = []
cnt = 0
for pair in B:
    d = []
    for x in pair:
        for j, s in enumerate(S):
            if x in s:
                d.append(j)

    if len(d) <= 0:
        pt.append(1)
        S.append(set(pair))
    elif len(d) == 1:
        pt.append(len(S[d[0]]))
        S[d[0]].add(pair[0])
        S[d[0]].add(pair[1])
    else:
        if d[0] == d[1]:
            pt.append(0)
        else:
            pt.append(len(S[d[0]]) * len(S[d[1]]))
            S[d[0]] = S[d[0]].union(S[d[1]])
            del S[d[1]]

cnt = 0
for x in pt[::-1]:
    cnt += x
    print(cnt)


Fixed submission:
N, M = map(int, input().split())
B = [list(map(int, input().split())) for _ in range(M)]

pt = []
G = [[None, 1] for x in range(N+1)]

def find(x):
    n = G[x]
    c = []
    while not n[0] is None:
        c.append(n)
        n = n[0]
    for ci in c:
        ci[0] = n
    return n

cnt = 0
while len(B):
    x, y = B.pop()
    wx = find(x)
    wy = find(y)
    if wx is wy:
        pt.append(0)
    else:
        pt.append(wx[1] * wy[1])
        wx[1] += wy[1]
        wy[0] = wx

    #print(G)

cnt = 0
for _ in range(M):
    cnt += pt.pop()
    print(cnt)