Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100000)
input=sys.stdin.readline
n,m=map(int,input().split())
l=[1]*n
z=n*(n-1)//2
input()
m-=1
b=[input().split() for _ in range(m)]
c=[0]*m+[z]
def r(s):
  t=l[s]
  if t>0:
    return s
  else:
    l[s]=r(t)
    return l[s]
def f(s):
  return r(int(s)-1)
for i in range(m-1,-1,-1):
  x,y=map(f,b[i])
  if x!=y:
    s,t=l[x],l[y]
    z-=s*t
    if s<t:
      l[x]=-y
      l[y]+=s
    else:
      l[y]=-x
      l[x]+=t
  c[i]=z
for x in c:
  print(x)

Fixed submission:
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline
n,m=map(int,input().split())
z=n*(n-1)//2
l=[-1]*n
a=[1]*n
b=[input().split() for _ in range(m)]
c=[0]*m+[z]
def r(s):
  t=l[s]
  if t<0:
    return s
  else:
    l[s]=r(t)
    return l[s]
def f(s):
  return r(int(s)-1)
for i in range(m-1,-1,-1):
  x,y=map(f,b[i])
  if x!=y:
    l[x]=y
    z-=a[x]*a[y]
    a[y]+=a[x]
  c[i]=z
for x in c[1:]:
  print(x)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline
n,m=map(int,input().split())
z=n*(n-1)//2
l=[-1]*n
a=[1]*n
b=[input().split() for _ in range(m)]
c=[0]*m+[z]
def r(s):
  t=l[s]
  return s if t<0 else r(t)
def f(s):
  return r(int(s)-1)
for i in range(m-1,-1,-1):
  x,y=map(f,b[i])
  if x!=y:
    l[x]=y
    l=list(map(lambda w:y if w==x else w,l))
    z-=a[x]*a[y]
    a[y]+=a[x]
  c[i]=z
for x in c[1:]:
  print(x)

Fixed submission:
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline
n,m=map(int,input().split())
z=n*(n-1)//2
l=[-1]*n
a=[1]*n
b=[input().split() for _ in range(m)]
c=[0]*m+[z]
def r(s):
  t=l[s]
  if t<0:
    return s
  else:
    l[s]=r(t)
    return l[s]
def f(s):
  return r(int(s)-1)
for i in range(m-1,-1,-1):
  x,y=map(f,b[i])
  if x!=y:
    l[x]=y
    z-=a[x]*a[y]
    a[y]+=a[x]
  c[i]=z
for x in c[1:]:
  print(x)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline
n,m=map(int,input().split())
z=n*(n-1)//2
l=[-1]*n
a=[1]*n
b=[input().split() for _ in range(m)]
c=[0]*m+[z]
def f(x):
  x=int(x)-1
  s=x+0
  while(1):
    t=l[s]
    if t<0:
      l[x]=s
      return s
    s=t
for i in range(m-1,-1,-1):
  x,y=map(f,b[i])
  if x!=y:
    l[x]=y
    z-=a[x]*a[y]
    a[y]+=a[x]
  c[i]=z
for x in c[1:]:
  print(x)

Fixed submission:
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline
n,m=map(int,input().split())
z=n*(n-1)//2
l=[-1]*n
a=[1]*n
b=[input().split() for _ in range(m)]
c=[0]*m+[z]
def r(s):
  t=l[s]
  if t<0:
    return s
  else:
    l[s]=r(t)
    return l[s]
def f(s):
  return r(int(s)-1)
for i in range(m-1,-1,-1):
  x,y=map(f,b[i])
  if x!=y:
    l[x]=y
    z-=a[x]*a[y]
    a[y]+=a[x]
  c[i]=z
for x in c[1:]:
  print(x)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline
n,m=map(int,input().split())
z=n*(n-1)//2
l=[-1]*n
a=[1]*n
b=[input().split() for _ in range(m)]
c=[0]*m+[z]
def r(s):
  t=l[s]
  return s if t<0 else r(t)
def f(s):
  return r(int(s)-1)
for i in range(m-1,-1,-1):
  x,y=map(f,b[i])
  if x!=y:
    l[x]=y
    z-=a[x]*a[y]
    a[y]+=a[x]
  c[i]=z
for x in c[1:]:
  print(x)

Fixed submission:
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline
n,m=map(int,input().split())
z=n*(n-1)//2
l=[-1]*n
a=[1]*n
b=[input().split() for _ in range(m)]
c=[0]*m+[z]
def r(s):
  t=l[s]
  if t<0:
    return s
  else:
    l[s]=r(t)
    return l[s]
def f(s):
  return r(int(s)-1)
for i in range(m-1,-1,-1):
  x,y=map(f,b[i])
  if x!=y:
    l[x]=y
    z-=a[x]*a[y]
    a[y]+=a[x]
  c[i]=z
for x in c[1:]:
  print(x)

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
ans=(n*(n-1))//2
l=[-1]*n
a=[1]*n
b=[input().split() for _ in range(m)]
c=[0]*m+[ans]
def r(s):
  t=l[s]
  return s if t<0 else r(t)
def f(s):
  return r(int(s)-1)
for i in range(m-1,-1,-1):
  x,y=map(f,b[i])
  if x!=y:
    l[x]=y
    ans-=a[x]*a[y]
    a[y]+=a[x]
  c[i]=ans
for x in c[1:]:
  print(x)

Fixed submission:
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline
n,m=map(int,input().split())
z=n*(n-1)//2
l=[-1]*n
a=[1]*n
b=[input().split() for _ in range(m)]
c=[0]*m+[z]
def r(s):
  t=l[s]
  if t<0:
    return s
  else:
    l[s]=r(t)
    return l[s]
def f(s):
  return r(int(s)-1)
for i in range(m-1,-1,-1):
  x,y=map(f,b[i])
  if x!=y:
    l[x]=y
    z-=a[x]*a[y]
    a[y]+=a[x]
  c[i]=z
for x in c[1:]:
  print(x)

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
ans=n*(n-1)/2
l=[-1]*n
a=[1]*n
b=[input().split() for _ in range(m)]
c=[0]*m+[ans]
def r(s):
  t=l[s]
  return s if t<0 else r(t)
def f(s):
  return r(int(s)-1)
for i in range(m-1,-1,-1):
  x,y=map(f,b[i])
  if x!=y:
    l[x]=y
    ans-=a[x]*a[y]
    a[y]+=a[x]
  c[i]=ans
for x in c[1:]:
  print(x)

Fixed submission:
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline
n,m=map(int,input().split())
z=n*(n-1)//2
l=[-1]*n
a=[1]*n
b=[input().split() for _ in range(m)]
c=[0]*m+[z]
def r(s):
  t=l[s]
  if t<0:
    return s
  else:
    l[s]=r(t)
    return l[s]
def f(s):
  return r(int(s)-1)
for i in range(m-1,-1,-1):
  x,y=map(f,b[i])
  if x!=y:
    l[x]=y
    z-=a[x]*a[y]
    a[y]+=a[x]
  c[i]=z
for x in c[1:]:
  print(x)

Buggy python submission (verdict: Runtime Error):
def root(s):
  t=l[s]
  if t<0:
    return s
  return root(t)
def f(s):
  return root(int(s)-1)
n,m=map(int,input().split())
ans=n*(n-1)//2
l=[-1]*n
a=[1]*n
b=[input().split() for _ in range(m)]
c=[0]*m+[ans]
for i in range(m-1,-1,-1):
  x,y=map(f,b[i])
  if x!=y:
    l[x]=y
    ans-=a[x]*a[y]
    a[y]+=a[x]
  c[i]=ans
for x in c[1:]:
  print(x)

Fixed submission:
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline
n,m=map(int,input().split())
z=n*(n-1)//2
l=[-1]*n
a=[1]*n
b=[input().split() for _ in range(m)]
c=[0]*m+[z]
def r(s):
  t=l[s]
  if t<0:
    return s
  else:
    l[s]=r(t)
    return l[s]
def f(s):
  return r(int(s)-1)
for i in range(m-1,-1,-1):
  x,y=map(f,b[i])
  if x!=y:
    l[x]=y
    z-=a[x]*a[y]
    a[y]+=a[x]
  c[i]=z
for x in c[1:]:
  print(x)

Buggy python submission (verdict: Runtime Error):
def root(s):
  t=l[s]
  if t<0:
    return s
  return root(t)
def f(s):
  return root(int(s)-1)
n,m=map(int,input().split())
ans=n*(n-1)//2
l=[-1]*n
a=[1]*n
b=[input().split() for _ in range(m)]
c=[0]*m+[ans]
for i in range(m-1,-1,-1):
  x,y=map(f,b[i+1])
  if x!=y:
    l[x]=y
    ans-=a[x]*a[y]
    a[y]+=a[x]
  c[i]=ans
for x in c[1:]:
  print(x)

Fixed submission:
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline
n,m=map(int,input().split())
z=n*(n-1)//2
l=[-1]*n
a=[1]*n
b=[input().split() for _ in range(m)]
c=[0]*m+[z]
def r(s):
  t=l[s]
  if t<0:
    return s
  else:
    l[s]=r(t)
    return l[s]
def f(s):
  return r(int(s)-1)
for i in range(m-1,-1,-1):
  x,y=map(f,b[i])
  if x!=y:
    l[x]=y
    z-=a[x]*a[y]
    a[y]+=a[x]
  c[i]=z
for x in c[1:]:
  print(x)

Buggy python submission (verdict: Runtime Error):
def root(s):
  t=l[s]
  if t<0:
    return s
  return root(t)
n,m=map(int,input().split())
ans=n*(n-1)//2
l=[-1]*n
a=[1]*n
b=[input().split() for _ in range(m)]
c=[ans]*m
for i in range(m-2,-1,-1):
  x,y=map(int,b[i+1])
  x=root(x-1)
  y=root(y-1)
  if x!=y:
    l[x]=y
    ans-=a[x]*a[y]
    a[y]+=a[x]
  c[i]=ans
for x in c:
  print(x)

Fixed submission:
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline
n,m=map(int,input().split())
z=n*(n-1)//2
l=[-1]*n
a=[1]*n
b=[input().split() for _ in range(m)]
c=[0]*m+[z]
def r(s):
  t=l[s]
  if t<0:
    return s
  else:
    l[s]=r(t)
    return l[s]
def f(s):
  return r(int(s)-1)
for i in range(m-1,-1,-1):
  x,y=map(f,b[i])
  if x!=y:
    l[x]=y
    z-=a[x]*a[y]
    a[y]+=a[x]
  c[i]=z
for x in c[1:]:
  print(x)

Buggy python submission (verdict: Runtime Error):
def root(s):
  t=l[s]
  if not t:
    return s
  return root(t)
n,m=map(int,input().split())
ans=n*(n-1)//2
l=[0]*n
a=[1]*n
b=[input().split() for _ in range(m)]
c=[ans]*m
for i in range(m-2,-1,-1):
  x,y=map(int,b[i+1])
  x=root(x-1)
  y=root(y-1)
  if x!=y:
    l[x]=y
    ans-=a[x]*a[y]
    a[y]+=a[x]
  c[i]=ans
for x in c:
  print(x)

Fixed submission:
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline
n,m=map(int,input().split())
z=n*(n-1)//2
l=[-1]*n
a=[1]*n
b=[input().split() for _ in range(m)]
c=[0]*m+[z]
def r(s):
  t=l[s]
  if t<0:
    return s
  else:
    l[s]=r(t)
    return l[s]
def f(s):
  return r(int(s)-1)
for i in range(m-1,-1,-1):
  x,y=map(f,b[i])
  if x!=y:
    l[x]=y
    z-=a[x]*a[y]
    a[y]+=a[x]
  c[i]=z
for x in c[1:]:
  print(x)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split(' '))
l = [set(map(int, input().split(' '))) for _ in range(m)]
max_useless = n*(n-1)//2
ll = [[l[-1]]]

for i in range(2, m):
  x = ll[-1]
  ind = []
  se = l[-i]
  for j in range(len(x)):
    if x[j] & se:
      ind.append(j)
  if not ind:
    ll.append(ll[-1] + [se])
  else:
    for j in ind:
      se = se | x[j]
    ll.append([x[j] for j in range(len(x)) if j not in ind] + [se])

def func(lis):
  count = 0
  for x in lis:
    y = len(x)
    count += y*(y-1)//2
  return max_useless - count

for i in range(1, m):
  print(func(ll[-i]))
print(max_useless)

Fixed submission:
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline
n,m=map(int,input().split())
z=n*(n-1)//2
l=[-1]*n
a=[1]*n
b=[input().split() for _ in range(m)]
c=[0]*m+[z]
def r(s):
  t=l[s]
  if t<0:
    return s
  else:
    l[s]=r(t)
    return l[s]
def f(s):
  return r(int(s)-1)
for i in range(m-1,-1,-1):
  x,y=map(f,b[i])
  if x!=y:
    l[x]=y
    z-=a[x]*a[y]
    a[y]+=a[x]
  c[i]=z
for x in c[1:]:
  print(x)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split(' '))
l = [set(map(int, input().split(' '))) for _ in range(m)]
max_useless = n*(n-1)//2
ll = [[l[-1]]]

for i in range(2, m+1):
  x = ll[-1]
  ind = []
  se = l[-i]
  for j in range(len(x)):
    if x[j] & se:
      ind.append(j)
  #print(ind)
  if not ind:
    ll.append(ll[-1] + [se])
  else:
    #print(0, ll)
    for j in ind:
      se = se | x[j]
    ll.append([x[j] for j in range(len(x)) if j not in ind] + [se])

def func(lis):
  count = 0
  for x in lis:
    y = len(x)
    count += y*(y-1)//2
  return max_useless - count

#print(ll)
for i in range(2, m+1):
  #print(ll[-i])
  print(func(ll[-i]))
print(max_useless)

Fixed submission:
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline
n,m=map(int,input().split())
z=n*(n-1)//2
l=[-1]*n
a=[1]*n
b=[input().split() for _ in range(m)]
c=[0]*m+[z]
def r(s):
  t=l[s]
  if t<0:
    return s
  else:
    l[s]=r(t)
    return l[s]
def f(s):
  return r(int(s)-1)
for i in range(m-1,-1,-1):
  x,y=map(f,b[i])
  if x!=y:
    l[x]=y
    z-=a[x]*a[y]
    a[y]+=a[x]
  c[i]=z
for x in c[1:]:
  print(x)