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: from math import factorial
  
  N, M = map(int, input().split())
  AB_list = [[]]
  for i in range(M):
      A, B = map(int, input().split())
      AB_list.append([A, B])
  del AB_list[0]
  AB_list.reverse()
  S_list = []
  result = []
  mixed = []
  
  i = 0
  while i < M:
      S_list.append(AB_list[i])
      if len(S_list) == 1:
          val_c = int(
              factorial(len(S_list[0])) / factorial(2) / factorial(len(S_list[0]) - 2)
          )
          result.append(val_c)
      else:
          count = 0
          change = 1
          switch = 0
          while change != 0 and switch == 0:
              change = 0
              for k in range(len(S_list) - 1):
                  list_and = list(set(S_list[k]) & set(S_list[len(S_list) - 1]))
                  if not len(list_and) == 0:
                      val = list(set(S_list[k]) | set(S_list[len(S_list) - 1]))
                      S_list.insert(k, val)
                      del S_list[k + 1 : k + 2]
                      del S_list[len(S_list) - 1]
                      change += 1
                      switch += 1
                      break
                  else:
                      pass
          while change != 0 and switch != 0:
              change = 0
              for k in range(len(S_list) - 1):
                  list_and = list(set(S_list[k + 1]) & set(S_list[0]))
                  if not len(list_and) == 0:
                      val = list(set(S_list[k + 1]) | set(S_list[0]))
                      del S_list[k + 1 : k + 2]
                      S_list.insert(0, val)
                      del S_list[1]
                      change += 1
                      break
                  else:
                      pass
          # print(S_list)
          val_total = 0
          for j in range(len(S_list)):
              val_c = int(
                  factorial(len(S_list[j])) / factorial(2) / factorial(len(S_list[j]) - 2)
              )
              val_total += val_c
          result.append(val_total)
  
      i += 1
  
  result.reverse()
  base_result = int(factorial(N) / factorial(2) / factorial(N - 2))
  for i in range(1, M):
      print(base_result - result[i])
  print(base_result)
  
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"}]