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: N, M = [int(e) for e in input().split(" ")]
  ABs = []
  for _ in range(M):
      ABs.append([int(e) for e in input().split(" ")])
  maxValue = N * (N - 1) // 2
  ans = [maxValue]
  buf_sets = []
  flagSkip = False
  for i in range(M - 1):
      a, b = ABs[M - 1 - i]
      # print("a,b", a, b)
      if flagSkip is True:
          ans.append(0)
          continue
  
      idx_a = None
      idx_b = None
      if len(buf_sets) > 0:
          for j, s in enumerate(buf_sets):
              if a in s:
                  idx_a = j
              if b in s:
                  idx_b = j
              if idx_a is not None and idx_b is not None:
                  break
      if idx_a is None and idx_b is None:
          s_new = set([a, b])
          buf_sets.append(s_new)
      elif idx_a is not None and idx_b is None:
          buf_sets[idx_a].add(a)
          buf_sets[idx_a].add(b)
      elif idx_a is None and idx_b is not None:
          buf_sets[idx_b].add(a)
          buf_sets[idx_b].add(b)
      else:
          s_a = buf_sets[idx_a]
          s_b = buf_sets[idx_b]
          buf_sets[idx_a] = s_a | s_b
          buf_sets.pop(idx_b)
  
      # for s in buf_sets:
      #     print(s)
      # print("---")
  
      count = 0
      for s in buf_sets:
          n = len(s)
          count = count + (n * (n - 1) // 2)
      d = maxValue - count
      ans.append(d)
      if d == 0:
          flagSkip = True
  
  for a in reversed(ans):
      print(a)
  
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"}]