qyliang/CodeNanoFix huggingface dataset:
# Buggy code:
def comb(N) :
    return N*(N+1)//2

class UnionFind:
    def __init__(self,N):
        self.parent = [i for i in range(N)]
        self.rank = [0] * N
        self.count = 0
        self.size = [1] * N
        self.connection = 0
    def root(self,a):
        if self.parent[a] == a:
            return a
        else:
            self.parent[a] = self.root(self.parent[a])
            return self.parent[a]
    def is_same(self,a,b):
        return self.root(a) == self.root(b)
    def unite(self,a,b):
        ra = self.root(a)
        rb = self.root(b)
        if ra == rb: return
        self.connection -= (comb(self.size[ra]) + comb(self.size[rb]))
        self.connection += comb(self.size[ra] + self.size[rb])
        if self.rank[ra] < self.rank[rb]:
            self.size[rb] += self.size[ra]
            self.parent[ra] = rb
        else:
            self.size[ra] += self.size[rb]
            self.parent[rb] = ra
            if self.rank[ra] == self.rank[rb]: self.rank[ra] += 1
        self.count += 1

N,M = map(int,input().split())
L = [list(map(int,input().split())) for i in range(M)]

UF = UnionFind(N)

ans = [N*(N-1)//2]

for i in range(M) :
    a,b = L[i]
    a -= 1
    b -= 1
    UF.unite(a,b)
    ans.append(ans[0] - UF.connection)

print(*ans[::-1][1:], sep="\n")


# Fixed code:
def comb(N) :
    return N*(N+1)//2

class UnionFind:
    def __init__(self,N):
        self.parent = [i for i in range(N)]
        self.rank = [0] * N
        self.count = 0
        self.size = [1] * N
        self.connection = 0
    def root(self,a):
        if self.parent[a] == a:
            return a
        else:
            self.parent[a] = self.root(self.parent[a])
            return self.parent[a]
    def is_same(self,a,b):
        return self.root(a) == self.root(b)
    def unite(self,a,b):
        ra = self.root(a)
        rb = self.root(b)
        if ra == rb: return
        self.connection -= (comb(self.size[ra]) + comb(self.size[rb]))
        self.connection += comb(self.size[ra] + self.size[rb])
        if self.rank[ra] < self.rank[rb]:
            self.size[rb] += self.size[ra]
            self.parent[ra] = rb
        else:
            self.size[ra] += self.size[rb]
            self.parent[rb] = ra
            if self.rank[ra] == self.rank[rb]: self.rank[ra] += 1
        self.count += 1

N,M = map(int,input().split())
L = [list(map(int,input().split())) for i in range(M)]

UF = UnionFind(N)

ans = [N*(N-1)//2]

for i in range(M-1,-1,-1) :
    a,b = L[i]
    a -= 1
    b -= 1
    UF.unite(a,b)
    ans.append(ans[0] - UF.connection)

print(*ans[::-1][1:], sep="\n")
# Buggy code:
n,m=map(int,input().split())
l=[]
for i in range(m):
  l.append(list(map(int,input().split())))
l=l[::-1]
parent=[i for i in range(n+1)]
depth=[1 for i in range(n+1)]
def find(n):
  if parent[n]==n:
    return n
  else:
    parent[n]=find(parent[n])
    return parent[n]
def unite(n,m):
  n1=find(n)
  m1=find(m)
  if n1==m1:
    return None
  elif depth[n1]<depth[m1]:
    parent[n1]=m1
    depth[m1]+=depth[n1]
  else:
    parent[m1]=n1
    depth[n1]+=depth[m1]
sum=n*(n-1)//2
ans=[]
for i in range(m):
  ans.append(sum)
  l1=l[i]
  a,b=l1[0],l1[1]
  a1=find(a)
  b1=find(b)
  sum-=depth[a1]*depth[b1]
  unite(a,b)
for i in range(1,m+1):
  print(ans[-i])

# Fixed code:
n,m=map(int,input().split())
l=[]
for i in range(m):
  l.append(list(map(int,input().split())))
l=l[::-1]
parent=[i for i in range(n+1)]
depth=[1 for i in range(n+1)]
def find(n):
  if parent[n]==n:
    return n
  else:
    parent[n]=find(parent[n])
    return parent[n]
def unite(n,m):
  n1=find(n)
  m1=find(m)
  if n1==m1:
    return None
  elif depth[n1]<depth[m1]:
    parent[n1]=m1
    depth[m1]+=depth[n1]
  else:
    parent[m1]=n1
    depth[n1]+=depth[m1]
sum=n*(n-1)//2
ans=[]
for i in range(m):
  ans.append(sum)
  l1=l[i]
  a,b=l1[0],l1[1]
  a1=find(a)
  b1=find(b)
  if a1==b1:
    pass
  else:
    sum-=depth[a1]*depth[b1]
    unite(a,b)
for i in range(1,m+1):
  print(ans[-i])
# Buggy code:
n, m=map(int, input().split())
a=[0 for i in range(m)]
b=[0 for i in range(m)]
g=[list() for i in range(1+n)]
#print(g)

par=[i for i in range(m)]
cnt_con=[1 for i in range(m)]

def root(x):
    if x==par[x]:
        return x
    else:
        par[x]=root(par[x])
        return par[x]
def connect(x,y):
    #par[x]=root(x)
    #par[y]=root(y)
    if root(x)==root(y):
        0
    else:
        cnt_con[root(y)]+=cnt_con[root(x)]
        par[root(x)]=root(y)      
    return

for i in range(m):
    a[i], b[i]=map(int, input().split())
    a[i], b[i]=a[i]-1, b[i]-1

tmp=int(n*(n-1)/2)
ans=[0]*m
ans[-1]=tmp
ans[0]=0
#print('a,b=',a,b)
for i in range(m-1,-1,-1):
    ans[i]=tmp
    if root(a[i])==root(b[i]):
        0
    else:
        tmp-=cnt_con[root(a[i])]*cnt_con[root(b[i])]
    connect(a[i],b[i])
    #print('i,tmp',i,(a[i],b[i]),ans[i],tmp,par,cnt_con)
    
        
    
for i in range(m):
    print(ans[i])

# Fixed code:
import sys
sys.setrecursionlimit(100000)

n, m=map(int, input().split())
a=[0 for i in range(m)]
b=[0 for i in range(m)]
g=[list() for i in range(1+n)]
#print(g)

par=[i for i in range(n)]
cnt_con=[1 for i in range(n)]

def root(x):
    if x==par[x]:
        return x
    else:
        par[x]=root(par[x])
        return par[x]
def connect(x,y):
    #par[x]=root(x)
    #par[y]=root(y)
    if root(x)==root(y):
        0
    else:
        cnt_con[root(y)]+=cnt_con[root(x)]
        par[root(x)]=root(y)      
    return

for i in range(m):
    a[i], b[i]=map(int, input().split())
    a[i], b[i]=a[i]-1, b[i]-1


tmp=int(n*(n-1)/2)
ans=[0]*m
ans[-1]=tmp
#ans[0]=0
#print('a,b=',a,b)
for i in range(m-1,-1,-1):
    ans[i]=tmp
    if root(a[i])==root(b[i]):
        0
    else:
        tmp-=cnt_con[root(a[i])]*cnt_con[root(b[i])]
    connect(a[i],b[i])
    #print('i,tmp',i,(a[i],b[i]),ans[i],tmp,par,cnt_con)
    

    
for i in range(m):
    print(ans[i])
# Buggy code:
from sys import stdin
N, M = [int(x) for x in stdin.readline().rstrip().split()]
data = [stdin.readline().rstrip().split() for _ in range(M)]
print(data)

island = list(range(N))
counts = [1] * N
total = int((N * (N - 1)) / 2)
result = []

for c in reversed(data):
    ref0 = int(c[0]) - 1
    while island[ref0] != ref0:
        ref0 = island[ref0]
    ref1 = int(c[1]) - 1
    while island[ref1] != ref1:
        ref1 = island[ref1]

    if ref0 == ref1:
        result.append(0);
    else:
        island[max(ref0,ref1)] = min(ref0, ref1)
        result.append(counts[ref0] * counts[ref1]);
        counts[min(ref0,ref1)] = counts[ref0] + counts[ref1]

res = [total]
for r in result:
    res.append((res[-1] - r))

print('\n'.join(reversed([str(x) for x in res])))


# Fixed code:
from sys import stdin
N, M = [int(x) for x in stdin.readline().rstrip().split()]
data = [stdin.readline().rstrip().split() for _ in range(M)]

island = list(range(N))
counts = [1] * N
total = int((N * (N - 1)) / 2)
result = []

for c in reversed(data):
    ref0 = int(c[0]) - 1
    while island[ref0] != ref0:
        ref0 = island[ref0]
    ref1 = int(c[1]) - 1
    while island[ref1] != ref1:
        ref1 = island[ref1]

    if ref0 == ref1:
        result.append(0);
    else:
        island[max(ref0,ref1)] = min(ref0, ref1)
        result.append(counts[ref0] * counts[ref1]);
        counts[min(ref0,ref1)] = counts[ref0] + counts[ref1]

res = [total]
for r in result:
    res.append((res[-1] - r))

print('\n'.join(reversed([str(x) for x in res][:-1])))
# Buggy code:
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 code:
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]
d=[i for i in range(n)]
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]=d[y]
    d[y]=d[x]
    z-=a[x]*a[y]
    a[y]+=a[x]
  c[i]=z
for x in c[1:]:
  print(x)
# Buggy code:
import copy
N, M = map(int, input().split())
A = []
B = []
for i in range(M):
    a, b = map(int, input().split())
    A.append(a - 1)
    B.append(b - 1)


class UnionFind:
    def __init__(self, n):
        self.Parent = [-1 for i in range(N)]

    def root(self, x):
        if self.Parent[x] < 0:
            return x
        self.Parent[x] = self.root(self.Parent[x])
        return copy.deepcopy(self.Parent[x])

    def size(self, x):
        return -copy.deepcopy(self.Parent[self.root(x)])

    def connect(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False
        if self.size(x) < self.size(y):
            x, y = y, x
        self.Parent[x] += self.deepcopy(self.Parent[y])
        self.Parent[y] = x
        return True


ans = [0 for i in range(M)]
ans[M - 1] = N * (N - 1) / 2
unif = UnionFind(N)

for i in range(M-1, 1, -1):
    ans[i - 1] = ans[i]
    if unif.root(A[i]) != unif.root(B[i]):
        ans[i - 1] -= unif.size(A[i]) * unif.size(B[i])
        unif.connect(A[i], B[i])

for i in range(M):
    print(int(ans[i]))


# Fixed code:
import copy
N, M = map(int, input().split())
A = []
B = []
for i in range(M):
    a, b = map(int, input().split())
    A.append(a - 1)
    B.append(b - 1)


class UnionFind:
    def __init__(self, n):
        self.Parent = [-1 for i in range(N)]

    def root(self, x):
        if self.Parent[x] < 0:
            return x
        self.Parent[x] = self.root(self.Parent[x])
        return copy.deepcopy(self.Parent[x])

    def size(self, x):
        return -copy.deepcopy(self.Parent[self.root(x)])

    def connect(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False
        if self.size(x) < self.size(y):
            x, y = y, x
        self.Parent[x] += copy.deepcopy(self.Parent[y])
        self.Parent[y] = x
        return True


ans = [0 for i in range(M)]
ans[M - 1] = N * (N - 1) / 2
unif = UnionFind(N)

for i in range(M-1, 0, -1):
    ans[i - 1] = ans[i]
    if unif.root(A[i]) != unif.root(B[i]):
        ans[i - 1] -= unif.size(A[i]) * unif.size(B[i])
        unif.connect(A[i], B[i])

for i in range(M):
    print(int(ans[i]))
# Buggy code:
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 code:
n,m=map(int,input().split())
l=[-1]*n
b=[input().split() for _ in range(m)]
c=[0]*m+[n*(n-1)//2]
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])
  s,t=0,0
  if x!=y:
    s,t=l[x],l[y]
    if s>t:
      l[x]=y
      l[y]+=s
    else:
      l[y]=x
      l[x]+=t
  c[i]=c[i+1]-s*t
for x in c[1:]:
  print(x)
# Buggy code:
    import sys
    sys.setrecursionlimit(100000)
    n,m = map(int,input().split())
    a = [0]*m
    b = [0]*m
    for i in range(m):
      u,v = map(int, input().split())
      a[i] = u-1
      b[i] = v-1
    par = [i for i in range(n)]
    size = [1]*n
    incomb = [n*(n-1)//2]*m
     
    def root(x):
      if par[x] == x: 
        return x
      else:
        par[x] = root(par[x])
        return par[x]
        
    def isSame(x,y):
      return par[x] == par[y]
     
    def union(x,y):
      x = root(x)
      y = root(y)
      if x == y:
        return
      else:
        par[y] = x
        size[x] += size[y]
        
    def size_count(x):
      return size[root(x)]
     
    for i in reversed(range(1,m)):
      q_a = a[i]
      q_b = b[i]
      size_a = size_count(q_a)
      size_b = size_count(q_b)
      if not isSame(q_a,q_b):
        union(q_a,q_b)
        incomb[i-1] = incomb[i] - size_a*size_b
      else:
        incomb[i-1] = incomb[i]
     
    for i in incomb:
      print(i)

# Fixed code:
import sys
sys.setrecursionlimit(1000000)
n,m = map(int,input().split())
a = [0]*m
b = [0]*m
for i in range(m):
  u,v = map(int, input().split())
  a[i] = u-1
  b[i] = v-1
par = [i for i in range(n)]
size = [1]*n
incomb = [n*(n-1)//2]*m

def root(x):
  if par[x] == x: 
    return x
  else:
    par[x] = root(par[x])
    return par[x]
    
def isSame(x,y):
  return par[x] == par[y]

def union(x,y):
  x = root(x)
  y = root(y)
  if x == y:
    return
  else:
    par[y] = x
    size[x] += size[y]
    
def size_count(x):
  return size[root(x)]

for i in reversed(range(1,m)):
  q_a = a[i]
  q_b = b[i]
  size_a = size_count(q_a)
  size_b = size_count(q_b)
  if not isSame(q_a,q_b):
    union(q_a,q_b)
    incomb[i-1] = incomb[i] - size_a*size_b
  else:
    incomb[i-1] = incomb[i]

for i in incomb:
  print(i)
# Buggy code:
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(M)]
parts=[i for i in range(N)]
ans=[N*(N-1)//2]
parts_dict=dict([[i,[i]] for i in range(N)])

for i in range(M-1):
    ab=AB.pop()
    if parts[ab[0]-1]==parts[ab[1]-1]:
        ans.append(ans[-1])
    else:
        a,b=sorted(ab,key=lambda x:parts[x-1])
        len_a,len_b=len(parts_dict[parts[a-1]]),len(parts_dict[parts[b-1]])
        ans.append(ans[-1]-len_a*len_b)
        parts_dict[a-1]+=parts_dict[parts[b-1]]
        for i in parts_dict[parts[b-1]]:
            parts[i]=parts[a-1]

for i in range(M-2):
    if ans[i+1]==ans[i+2]:
        ans[i+1]=ans[i]

for i in reversed(ans):
    print(i)

# Fixed code:
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(M)]
parts=[i for i in range(N)]
ans=[N*(N-1)//2]
parts_dict=dict([[i,[i]] for i in range(N)])

for i in range(M-1):
    ab=AB.pop()
    if parts[ab[0]-1]==parts[ab[1]-1]:
        ans.append(ans[-1])
    else:
        a,b=sorted(ab,key=lambda x:parts[x-1])
        len_a,len_b=len(parts_dict[parts[a-1]]),len(parts_dict[parts[b-1]])
        ans.append(ans[-1]-len_a*len_b)
        parts_dict[parts[a-1]]+=parts_dict[parts[b-1]]
        for i in parts_dict[parts[b-1]]:
            parts[i]=parts[a-1]

for i in reversed(ans):
    print(i)
# Buggy code:



class dset:
    def __init__(self,n):
        self.par = [-1]*n

    def size(self,n):
        return -self.par[self.root(n)]

    def root(self,n):
        return self.par[n] = root(par[n]) if self.par[n]>=0 else n

    def same(self, a, b):
        return self.root(a) == self.root(b)

    def __link__(self,a,b):
        if a == b:
            return 
        
        if self.size(a) < self.size(b):
            a,b = b,a
        
        self.par[a] += self.par[b]
        self.par[b] = a

    def unite(self,a,b):
        self.__link__(
            self.root(a)
            ,self.root(b)
            )


def main():
    n, m = map(int, input().split() ) 


    ins = [ list( map(int,input().split()) ) for i in range(m)  ]

    ds = dset(n)

    ans = [0]*m
    ans[-1] = n*(n-1)//2
    for i in range(m-1,0,-1):
        ans[i-1] = ans[i]

        a,b = ins[i]
        a-=1
        b-=1

#        print(ins[i])
       # print( (ds.root(a),ds.root(b)) ) 
        if not ds.same(a,b):
            x = ds.size(a)
            y = ds.size(b)
            #print((x,y))
            ans[i-1] -= x*y
            ds.unite(a,b)

    for e in ans:
        print(e)

if __name__ == '__main__':
    main()

# Fixed code:



class dset:
    def __init__(self,n):
        self.par = [-1]*n

    def size(self,n):
        return -self.par[self.root(n)]

    def root(self,n):
        if self.par[n]<0:
            return n
        else:
            self.par[n] = self.root(self.par[n])
            return self.par[n]

    def same(self, a, b):
        return self.root(a) == self.root(b)

    def __link__(self,a,b):
        if a == b:
            return 
        
        if self.size(a) < self.size(b):
            a,b = b,a
        
        self.par[a] += self.par[b]
        self.par[b] = a

    def unite(self,a,b):
        self.__link__(
            self.root(a)
            ,self.root(b)
            )


def main():
    n, m = map(int, input().split() ) 


    ins = [ list( map(int,input().split()) ) for i in range(m)  ]

    ds = dset(n)

    ans = [0]*m
    ans[-1] = n*(n-1)//2
    for i in range(m-1,0,-1):
        ans[i-1] = ans[i]

        a,b = ins[i]
        a-=1
        b-=1

#        print(ins[i])
       # print( (ds.root(a),ds.root(b)) ) 
        if not ds.same(a,b):
            x = ds.size(a)
            y = ds.size(b)
            #print((x,y))
            ans[i-1] -= x*y
            ds.unite(a,b)

    for e in ans:
        print(e)

if __name__ == '__main__':
    main()
# Buggy code:
class UnionFind(object):
    def __init__(self, n):
        self.parent = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for i in range(n)]
        self.value=n*(n-1)//2


    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            return self.find(self.parent[x])


    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        self.value-=self.size[y]*self.size[x]
        self.size[x]+=self.size[y]
        self.size[y]=self.size[x]

        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)

n, m  =  map(int, input().split())
U=UnionFind(n)
ans=[U.value]
for i in range(m-1):
    a, b = map(int, input().split())
    U.unite(a-1, b-1)
    ans.append(U.value)
for i in ans[::-1]:
    print(i)

# Fixed code:
class UnionFind(object):
    def __init__(self, n):
        self.parent = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for i in range(n)]
        self.value=n*(n-1)//2


    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            return self.find(self.parent[x])


    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        self.value-=self.size[y]*self.size[x]
        self.size[x]+=self.size[y]
        self.size[y]=self.size[x]

        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)

n, m  =  map(int, input().split())
U=UnionFind(n)
ans=[U.value]
ab = [list(map(int, input().split())) for _ in range(m)]
for abi in ab[:0:-1]:
    a, b = abi
    U.unite(a-1, b-1)
    ans.append(U.value)
for i in ans[::-1]:
    print(i)
# Buggy code:
N, M = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(M)]

class UnionFind:
    def __init__(self, size):
        self.rank = [-1]*(size+1)
        self.number = [1]*(size+1)
        
    def find(self, x):
        while self.rank[x] >= 0:
            x = self.rank[x]
        return x
    
    def union(self, a, b):
        if a == b:
            return
        if self.rank[a] == self.rank[b]:
            self.rank[b] = a
            self.rank[a] -= 1
            self.number[a] += self.number[b]
        elif self.rank[a] < self.rank[b]:
            self.rank[b] = a
            self.number[a] += self.number[b]
        else:
            self.rank[a] = b
            self.number[b] += sekf.number[a]
            
p = N * (N - 1) // 2
ans = [p]
uf = UnionFind(N)

for a, b in ab[::-1]:
    ar = uf.find(a)
    br = uf.find(b)
    
    if ar != br:
        p -= uf.number[ar] * uf.number[br]
        uf.union(ar, br)
    ans.append(p)

print(*ans[::-1], sep='\n')

# Fixed code:
N, M = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(M)]

class UnionFind:
    def __init__(self, size):
        self.rank = [-1]*(size+1)
        self.number = [1]*(size+1)
        
    def find(self, x):
        while self.rank[x] >= 0:
            x = self.rank[x]
        return x
    
    def union(self, a, b):
        if a == b:
            return
        if self.rank[a] == self.rank[b]:
            self.rank[b] = a
            self.rank[a] -= 1
            self.number[a] += self.number[b]
        elif self.rank[a] < self.rank[b]:
            self.rank[b] = a
            self.number[a] += self.number[b]
        else:
            self.rank[a] = b
            self.number[b] += self.number[a]
            
p = N * (N - 1) // 2
ans = [p]
uf = UnionFind(N)

for a, b in ab[::-1]:
    ar = uf.find(a)
    br = uf.find(b)
    
    if ar != br:
        p -= uf.number[ar] * uf.number[br]
        uf.union(ar, br)
    ans.append(p)

print(*ans[::-1][1:], sep='\n')
# Buggy code:
class UnionFind():
  def __init__(self,n):
    self.parents = list(range(n))
    self.size = [1]*n
  
  def find(self,x):
    if self.parents[x] == x:
      return x
	
    self.parents[x] = self.find(self.parents[x])
    return self.parents[x]
  
  def union(self,x,y):
    x = self.find(x)
    y = self.find(y)
    
    if x==y:
      return
    
    if self.size[x]>self.size[y]:
      x,y=y,x
	
    self.size[x]+=self.size[y]
    self.parents[y] = x
  
  def sizeofset(self,x):
    return self.size[self.find(x)]


N,M=map(int,input().split())
uf = UnionFind(N)

cnt=(N)*(N-1)//2
L=[[int(x) for x in input().split()] for _ in range(M)]
ans=[]

for a,b in L[::-1]:
  ans.append(cnt)
  if uf.find(a)!=uf.find(b):
    cnt-= uf.sizeofset(a)*uf.sizeofset(b)
    uf.union(a,b)

for x in ans[::-1]:
  print(x)

# Fixed code:
class UnionFind():
  def __init__(self,n):
    self.parents = list(range(n))
    self.size = [1]*n
  
  def find(self,x):
    if self.parents[x] == x:
      return x
	
    self.parents[x] = self.find(self.parents[x])
    return self.parents[x]
  
  def union(self,x,y):
    x = self.find(x)
    y = self.find(y)
    
    if x==y:
      return
    
    if self.size[x]<self.size[y]:
      x,y=y,x
	
    self.size[x]+=self.size[y]
    self.parents[y] = x
  
  def same(self,x,y):
    return self.find(x) == self.find(y)
  
  def sizeofset(self,x):
    return self.size[self.find(x)]


N,M=map(int,input().split())
uf = UnionFind(N+1)

cnt=(N)*(N-1)//2
L=[[int(x) for x in input().split()] for _ in range(M)]
ans=[]

for a,b in L[::-1]:
  ans.append(cnt)
  if not uf.same(a,b):
    cnt -= uf.sizeofset(a)*uf.sizeofset(b)
    uf.union(a,b)

for x in ans[::-1]:
  print(x)
# Buggy code:
N = input().split(" ")
A = int(N[0])
B = int(N[1])

if B % A == 0:
    ans = B - A
else:
    ans = A + B

print(ans)

# Fixed code:
N = input().split(" ")
A = int(N[0])
B = int(N[1])

if B % A == 0:
    ans = B + A
else:
    ans = B - A

print(ans)
# Buggy code:
a,b=map(int,input().split())
if a % b == 0:
    print(a+b)
else:
   print(b-a)

# Fixed code:
a, b = map(int, input().split())

if b % a == 0:
    print(a + b)

else:
    print(b - a)
# Buggy code:
A,B=map(int,input().split())
if A%B==0:
    print(A+B)
else:
    print(B-A)

# Fixed code:
A,B = map(int,input().split())
if B%A == 0:
  print(A+B)
else:
  print(B-A)
# Buggy code:
A,B=map(int, input().split())
if A%B==0:
  print(A+B)
else:
  print(B-A)

# Fixed code:
A, B = list(map(int,input().split()))
if B % A == 0:
  print( A + B )
else:
  print( B - A )
# Buggy code:
a,b=(int(x) for x in input().split())

if a//b==0:
  print(a+b)
  
else:
  print(b-a)

# Fixed code:
a,b = (int(x) for x in input().split())

if b%a == 0 :
    print(a+b)

else:
    print(b-a)
# Buggy code:
A, B = map(int, input().split())
1 <= B <= A <= 20
 
if A % B == 0：
    print(A+B)
else:
    print(A-B)

# Fixed code:
A, B = map(int, input().split())
1 <= A <= B <= 20
 
if B % A == 0:
    print(A + B)
else:
    print(B - A)
# Buggy code:
A,B = map(int, input().split())
if B%A==0:
  print(A+B)
else:
  print(A-B)

# Fixed code:
A,B = map(int, input().split())
if(B%A==0):
    print(A+B)
else:
    print(B-A)