Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split(' '))
a = [0]*m
b = [0]*m
for i in range(m):
    a[i], b[i] = list(map(int, input().split(' ')))

c = [-1]*(m+1)

def find(num):
    if c[num] < 0:
        return num
    else:
        k = find(c[num])
        c[num] = k
    return k

result = [int(n*(n-1)/2)]
for i in range(m-1, 0,-1):
    x = find(a[i])
    y = find(b[i])

    if x != y:
        result.append(result[-1]-c[x]*c[y])
        x, y = sorted([x,y])
        c[x] += c[y]
        c[y] = x
    else:
        result.append(result[-1])

for i in result[::-1]:
    print(int(i))


Fixed submission:
n, m = map(int, input().split(' '))
a = [0]*m
b = [0]*m
for i in range(m):
    a[i], b[i] = list(map(int, input().split(' ')))

c = [-1]*(m+2)

def find(num):
    if c[num] < 0:
        return num
    else:
        k = find(c[num])
        c[num] = k
        return k

result = [int(n*(n-1)/2)]
for i in range(m-1, 0,-1):
    x = find(a[i])
    y = find(b[i])

    if x != y:
        result.append(result[-1]-c[x]*c[y])
        x, y = sorted([x,y])
        c[x] += c[y]
        c[y] = x
    else:
        result.append(result[-1])

for i in result[::-1]:
    print(int(i))

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split(' '))
a = [0]*m
b = [0]*m
for i in range(m):
    a[i], b[i] = list(map(int, input().split(' ')))

c = [-1]*(m+1)

def find(num):
    if c[num] < 0:
        return num
    else:
        k = find(c[num])
        c[num] = k
        return k

result = [int(n*(n-1)/2)]
for i in range(m-1, 0,-1):
    x = find(a[i])
    y = find(b[i])

    if x != y:
        result.append(result[-1]-c[x]*c[y])
        x, y = sorted([x,y])
        c[x] += c[y]
        c[y] = x
    else:
        result.append(result[-1])

for i in result[::-1]:
    print(int(i))


Fixed submission:
n, m = map(int, input().split(' '))
a = [0]*m
b = [0]*m
for i in range(m):
    a[i], b[i] = list(map(int, input().split(' ')))

c = [-1]*(m+2)

def find(num):
    if c[num] < 0:
        return num
    else:
        k = find(c[num])
        c[num] = k
        return k

result = [int(n*(n-1)/2)]
for i in range(m-1, 0,-1):
    x = find(a[i])
    y = find(b[i])

    if x != y:
        result.append(result[-1]-c[x]*c[y])
        x, y = sorted([x,y])
        c[x] += c[y]
        c[y] = x
    else:
        result.append(result[-1])

for i in result[::-1]:
    print(int(i))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split(' '))
s = [list(map(int, input().split(' '))) for _ in range(m)]
set_s = []
result = [n*(n-1)/2]
for i in range(m-1, 0, -1):
    x = set()
    y = set()
    j = 0
    check = 0
    while j < len(set_s):
        if set(s[i]) <= set_s[j]:
            result.append(result[-1])
            check = 1
            break
        elif {s[i][0]} <= set(set_s[j]):
            x = set_s.pop(j)
            j = 0
        elif {s[i][1]} <= set(set_s[j]):
            y = set_s.pop(j)
            j = 0
        else:
            j += 1
    if len(x) != 0 and len(y) != 0:
        result.append(result[-1]-len(x)*len(y))
        set_s.append(x|y)
    elif len(x) != 0:
        result.append(result[-1]-len(x))
        set_s.append(x|{s[i][1]})
    elif len(y) != 0:
        result.append(result[-1]-len(y))
        set_s.append(y|{s[i][0]})
    elif check == 0:
        set_s.append(set(s[i]))
        result.append(result[-1]-1)
for i in result[::-1]:
    print(int(i))

Fixed submission:
n, m = map(int, input().split(' '))
a = [0]*m
b = [0]*m
for i in range(m):
    a[i], b[i] = list(map(int, input().split(' ')))

c = [-1]*(m+2)

def find(num):
    if c[num] < 0:
        return num
    else:
        k = find(c[num])
        c[num] = k
        return k

result = [int(n*(n-1)/2)]
for i in range(m-1, 0,-1):
    x = find(a[i])
    y = find(b[i])

    if x != y:
        result.append(result[-1]-c[x]*c[y])
        x, y = sorted([x,y])
        c[x] += c[y]
        c[y] = x
    else:
        result.append(result[-1])

for i in result[::-1]:
    print(int(i))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split(' '))
s = [list(map(int, input().split(' '))) for _ in range(m)]

dic = [x for x in range(n)]
result = [int(n*(n-1)/2)]
for i in range(1,m):
    if dic[s[-1*i][0]-1] == dic[s[-1*i][1]-1]:
        result.append(result[-1])
    else:
#        p = [x for x in dic if x == dic[s[-1*i][0]-1]]
#        q = [x for x in dic if x == dic[s[-1*i][1]-1]]
        p = dic.count(dic[s[-1*i][0]-1])
        q = dic.count(dic[s[-1*i][1]-1])
        result.append(result[-1]-p*q)
        dic = [dic[s[-1*i][1]-1] if x == dic[s[-1*i][0]-1] else x for x in dic]
for i in range(1,m+1):
    print(result[-1*i])

Fixed submission:
n, m = map(int, input().split(' '))
a = [0]*m
b = [0]*m
for i in range(m):
    a[i], b[i] = list(map(int, input().split(' ')))

c = [-1]*(m+2)

def find(num):
    if c[num] < 0:
        return num
    else:
        k = find(c[num])
        c[num] = k
        return k

result = [int(n*(n-1)/2)]
for i in range(m-1, 0,-1):
    x = find(a[i])
    y = find(b[i])

    if x != y:
        result.append(result[-1]-c[x]*c[y])
        x, y = sorted([x,y])
        c[x] += c[y]
        c[y] = x
    else:
        result.append(result[-1])

for i in result[::-1]:
    print(int(i))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split(' '))
s = [list(map(int, input().split(' '))) for _ in range(m)]

dic = [x for x in range(n)]
result = [int(n*(n-1)/2)]
for i in range(1,m):
    if dic[s[-1*i][0]-1] == dic[s[-1*i][1]-1]:
        result.append(result[-1])
    else:
#        p = [x for x in dic if x == dic[s[-1*i][0]-1]]
#        q = [x for x in dic if x == dic[s[-1*i][1]-1]]
        p = dic.count(dic[s[-1*i][0]-1])
        q = dic.count(dic[s[-1*i][1]-1])
        result.append(result[-1]-p*q)
        if p<q:
            dic = [dic[s[-1*i][1]-1] if x == dic[s[-1*i][0]-1] else x for x in dic]
        else:
            dic = [dic[s[-1*i][0]-1] if x == dic[s[-1*i][1]-1] else x for x in dic]
for i in range(1,m+1):
    print(result[-1*i])

Fixed submission:
n, m = map(int, input().split(' '))
a = [0]*m
b = [0]*m
for i in range(m):
    a[i], b[i] = list(map(int, input().split(' ')))

c = [-1]*(m+2)

def find(num):
    if c[num] < 0:
        return num
    else:
        k = find(c[num])
        c[num] = k
        return k

result = [int(n*(n-1)/2)]
for i in range(m-1, 0,-1):
    x = find(a[i])
    y = find(b[i])

    if x != y:
        result.append(result[-1]-c[x]*c[y])
        x, y = sorted([x,y])
        c[x] += c[y]
        c[y] = x
    else:
        result.append(result[-1])

for i in result[::-1]:
    print(int(i))

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split(' '))
s = [list(map(int, input().split(' '))) for _ in range(m)]

dic = [x for x in range(n)]
result = [int(n*(n-1)/2)]
for i in range(1,m):
    if dic[s[-1*i][0]-1] == dic[s[-1*i][1]-1]:
        result.append(result[-1])
    else:
#        p = [x for x in dic if x == dic[s[-1*i][0]-1]]
#        q = [x for x in dic if x == dic[s[-1*i][1]-1]]
        p = x.count(dic[s[-1*i][0]-1])
        p = x.count(dic[s[-1*i][1]-1])
        result.append(result[-1]-len(p)*len(q))
        if len(p) < len(q):
            dic = [dic[s[-1*i][1]-1] if x == dic[s[-1*i][0]-1] else x for x in dic]
        else:
            dic = [dic[s[-1*i][0]-1] if x == dic[s[-1*i][1]-1] else x for x in dic]
for i in range(1,m+1):
    print(result[-1*i])

Fixed submission:
n, m = map(int, input().split(' '))
a = [0]*m
b = [0]*m
for i in range(m):
    a[i], b[i] = list(map(int, input().split(' ')))

c = [-1]*(m+2)

def find(num):
    if c[num] < 0:
        return num
    else:
        k = find(c[num])
        c[num] = k
        return k

result = [int(n*(n-1)/2)]
for i in range(m-1, 0,-1):
    x = find(a[i])
    y = find(b[i])

    if x != y:
        result.append(result[-1]-c[x]*c[y])
        x, y = sorted([x,y])
        c[x] += c[y]
        c[y] = x
    else:
        result.append(result[-1])

for i in result[::-1]:
    print(int(i))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split(' '))
s = [list(map(int, input().split(' '))) for _ in range(m)]

dic = [x for x in range(n)]
result = [int(n*(n-1)/2)]
for i in range(1,m):
    if dic[s[-1*i][0]-1] == dic[s[-1*i][1]-1]:
        result.append(result[-1])
    else:
        p = [x for x in dic if x == dic[s[-1*i][0]-1]]
        q = [x for x in dic if x == dic[s[-1*i][1]-1]]
        result.append(result[-1]-len(p)*len(q))
        if len(p) < len(q):
            dic = [dic[s[-1*i][1]-1] if x == dic[s[-1*i][0]-1] else x for x in dic]
        else:
            dic = [dic[s[-1*i][0]-1] if x == dic[s[-1*i][1]-1] else x for x in dic]
for i in range(1,m+1):
    print(result[-1*i])

Fixed submission:
n, m = map(int, input().split(' '))
a = [0]*m
b = [0]*m
for i in range(m):
    a[i], b[i] = list(map(int, input().split(' ')))

c = [-1]*(m+2)

def find(num):
    if c[num] < 0:
        return num
    else:
        k = find(c[num])
        c[num] = k
        return k

result = [int(n*(n-1)/2)]
for i in range(m-1, 0,-1):
    x = find(a[i])
    y = find(b[i])

    if x != y:
        result.append(result[-1]-c[x]*c[y])
        x, y = sorted([x,y])
        c[x] += c[y]
        c[y] = x
    else:
        result.append(result[-1])

for i in result[::-1]:
    print(int(i))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split(' '))
s = [list(map(int, input().split(' '))) for _ in range(m)]
for i in range(m):
    s[i] = [s[i][0]-1,s[i][1]-1]
dic = [0]*n
count = 1
out_result = [int(n*(n-1)/2)]
for i in range(m-1,0,-1):
    if dic[s[i][1]] == 0 and dic[s[i][0]]==0:
        dic[s[i][0]] = count
        dic[s[i][1]] = count
        count += 1
        out_result.append(out_result[-1]-1)
    elif dic[s[i][0]]==0 and dic[s[i][1]]!=0:
        c = [x for x in dic if x == dic[s[i][1]]]
        out_result.append(out_result[-1]-len(c))
        dic[s[i][0]] = dic[s[i][1]]
    elif dic[s[i][0]]!=0 and dic[s[i][1]]==0:
        c = [x for x in dic if x == dic[s[i][0]]]
        out_result.append(out_result[-1]-len(c))
        dic[s[i][1]] = dic[s[i][0]]
    elif dic[s[i][0]] == dic[s[i][1]]:
        out_result.append(out_result[-1])
    else:
        c = [x for x in dic if x == dic[s[i][0]]]
        d = [x for x in dic if x == dic[s[i][1]]]
        out_result.append(out_result[-1]-len(c)*len(d))
        a = int(dic[s[i][1]])
        b = int(dic[s[i][0]])
        dic = [a if x==b  else x  for x in dic]
for i in range(1,m+1):
    print(out_result[-1*i])

Fixed submission:
n, m = map(int, input().split(' '))
a = [0]*m
b = [0]*m
for i in range(m):
    a[i], b[i] = list(map(int, input().split(' ')))

c = [-1]*(m+2)

def find(num):
    if c[num] < 0:
        return num
    else:
        k = find(c[num])
        c[num] = k
        return k

result = [int(n*(n-1)/2)]
for i in range(m-1, 0,-1):
    x = find(a[i])
    y = find(b[i])

    if x != y:
        result.append(result[-1]-c[x]*c[y])
        x, y = sorted([x,y])
        c[x] += c[y]
        c[y] = x
    else:
        result.append(result[-1])

for i in result[::-1]:
    print(int(i))