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 UnionFindNode(object):
      def __init__(self, group_id, parent=None, value=None):
          self.group_id = group_id
          self.parent_ = parent
          self.value = value
          self.size_ = 1
  
      def __str__(self):
          return (
              "UnionFindNode(group_id: {}, \n\tparent: {}, value: {}, size: {})".format(
                  self.group_id, self.parent_, self.value, self.size_
              )
          )
  
      def is_root(self):
          return not self.parent_
  
      def parent(self):
          parent = self
          while parent.parent_:
              parent = parent.parent_
          if not self.is_root():
              self.parent_ = parent
          return parent
  
      def find(self):
          parent = self.parent()
          return parent.group_id
  
      def size(self):
          parent = self.parent()
          return parent.size_
  
      def unite(self, unite_node):
          parent = self.parent()
          unite_parent = unite_node.parent()
          if parent.group_id != unite_parent.group_id:
              if parent.size() > unite_parent.size():
                  unite_parent.parent_ = parent
                  parent.size_ = parent.size_ + unite_parent.size_
              else:
                  parent.parent_ = unite_parent
                  unite_parent.size_ = parent.size_ + unite_parent.size_
  
  
  [N, M] = list(map(int, input().split(" ")))
  bridge_list = []
  
  for _ in range(M):
      [a, b] = list(map(int, input().split(" ")))
      bridge_list.append((a - 1, b - 1))
  
  node_list = [UnionFindNode(i) for i in range(N)]
  combination_num = N * (N - 1) // 2
  combination_list = [combination_num]
  
  for bridge in bridge_list[:0:-1]:
      # print(bridge)
      if node_list[bridge[0]].find() != node_list[bridge[1]].find():
          combination_num = (
              combination_num - node_list[bridge[0]].size() * node_list[bridge[1]].size()
          )
          node_list[bridge[0]].unite(node_list[bridge[1]])
      combination_list.append(combination_num)
      # print(combination_num)
  
  for value in combination_list[::-1]:
      print(value)
  
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"}]