output_description: In the order i = 1, 2, ..., M, print the inconvenience just after the i-th
  bridge collapses. Note that the answer may not fit into a 32-bit integer type.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N M
      A_1 B_1
      A_2 B_2
      \vdots
      A_M B_M
attempt: class Node:
      def __init__(self, key):
          self.key = key
          self.parent = None
          self.rank = 0
          self.elements_count = 1
  
  
  class DisjointSet:
      def __init__(self, nodes):
          self.nodes = nodes
  
      def find_set(self, key):
          pivot = self.nodes[key]
          while pivot.key != pivot.parent.key:
              pivot = pivot.parent
          self.nodes[key].parent = pivot
          return pivot.key
  
      def elements_count(self, key):
          repr_key = self.find_set(key)
          return self.nodes[repr_key].elements_count
  
      def same(self, x, y):
          return self.find_set(x) == self.find_set(y)
  
      def unite(self, x, y):
          y_root = self.find_set(y)
          x_root = self.find_set(x)
          if self.nodes[x].rank > self.nodes[y].rank:
              self.nodes[y_root].parent = self.nodes[x_root]
              self.nodes[x_root].elements_count += self.nodes[y_root].elements_count
          elif self.nodes[x].rank < self.nodes[y].rank:
              self.nodes[x_root].parent = self.nodes[y_root]
              self.nodes[y_root].elements_count += self.nodes[x_root].elements_count
          else:
              self.nodes[x_root].parent = self.nodes[y_root]
              self.nodes[y_root].rank = self.nodes[y_root].rank + 1
              self.nodes[y_root].elements_count += self.nodes[x_root].elements_count
  
  
  def comb_pair(n):
      return (n * (n - 1)) // 2
  
  
  def m():
      N, M = [int(i) for i in input().split()]
      nodes = [Node(i) for i in range(0, N)]
      for node in nodes:
          node.parent = node
      ds = DisjointSet(nodes)
  
      convenience = [0] * (M + 1)
      inputs = [input().split() for _ in range(M)]
      inputs = [(int(x[0]) - 1, int(x[1]) - 1) for x in inputs]
      reversed_inputs = list(reversed(inputs))
      for i in range(M):
          a, b = reversed_inputs[i]
          if ds.same(a, b):
              convenience[i + 1] = convenience[i]
              next
          else:
              before = comb_pair(ds.elements_count(a)) + comb_pair(ds.elements_count(b))
              ds.unite(a, b)
              after = comb_pair(ds.elements_count(a))
              diff = after - before
              convenience[i + 1] = convenience[i] + diff
      maximum = convenience[-1]
      for c in convenience[-2::-1]:
          print(maximum - c)
  
  
  if __name__ == "__main__":
      m()
  
problem_description: Statement
  
  There are N islands and M bridges.
  
  The i-th bridge connects the A_i-th and B_i-th islands bidirectionally.
  
  Initially, we can travel between any two islands using some of these bridges.
  
  However, the results of a survey show that these bridges will all collapse
  because of aging, in the order from the first bridge to the M-th bridge.
  
  Let the **inconvenience** be the number of pairs of islands (a, b) (a < b)
  such that we are no longer able to travel between the a-th and b-th islands
  using some of the bridges remaining.
  
  For each i (1 \leq i \leq M), find the inconvenience just after the i-th
  bridge collapses.
samples: [{"input": "4 5\n    1 2\n    3 4\n    1 3\n    2 3\n    1 4", "output": "0\n    0\n    4\n    5\n    6\n    \n\nFor example, when the first to third bridges have collapsed, the inconvenience\nis 4 since we can no longer travel between the pairs (1, 2), (1, 3), (2, 4)\nand (3, 4).\n\n* * *"}, {"input": "6 5\n    2 3\n    1 2\n    5 6\n    3 4\n    4 5", "output": "8\n    9\n    12\n    14\n    15\n    \n\n* * *"}, {"input": "2 1\n    1 2", "output": "1"}]