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 = list(map(int, input().split()))
  isla = [0 for i in range(n + 1)]
  bri = []
  crus = [[] for i in range(n)]
  num = [0 for i in range(n)]
  score = []
  crusmax = 0
  
  plusnum = -1
  minusnum = -1
  newnum = -1
  plusval = [0, 0]
  minusval = [0, 0]
  
  
  for i in range(m):
      a, b = list(map(int, input().split()))
      bri.append([a, b])
  
  bri.reverse()
  # print(bri)
  
  for i in range(m):
      a = bri[i][0]
      b = bri[i][1]
      if isla[a] == 0 and isla[b] == 0:
          crusmax += 1
          crus[crusmax].append(a)
          crus[crusmax].append(b)
          isla[a] = crusmax
          isla[b] = crusmax
          num[crusmax] = 2
          [plusnum, minusnum, newnum] = [0, 0, crusmax]
      elif isla[a] == 0:
          isla[a] = isla[b]
          crus[isla[b]].append(a)
          num[isla[b]] += 1
          [plusnum, minusnum, newnum] = [isla[b], 0, 0]
          plusval = [num[isla[b]] - 1, num[isla[b]]]
      elif isla[b] == 0:
          isla[b] = isla[a]
          crus[isla[a]].append(b)
          num[isla[a]] += 1
          [plusnum, minusnum, newnum] = [isla[a], 0, 0]
          plusval = [num[isla[a]] - 1, num[isla[a]]]
      elif isla[a] < isla[b]:
          color = isla[b]
          dif = len(crus[isla[b]])
          for j in range(len(crus[isla[b]])):
              isla[crus[color][j]] = isla[a]
              crus[isla[a]].append(crus[color][j])
          crus[color] = []
          num[isla[a]] += num[color]
          num[color] = 0
          [plusnum, minusnum, newnum] = [isla[a], color, 0]
          plusval = [num[isla[a]] - dif, num[isla[a]]]
          minusval = [dif, 0]
      elif isla[a] > isla[b]:
          color = isla[a]
          dif = len(crus[isla[a]])
          for j in range(len(crus[isla[a]])):
              isla[crus[color][j]] = isla[b]
              crus[isla[b]].append(crus[color][j])
          crus[color] = []
          num[isla[b]] += num[color]
          num[color] = 0
          [plusnum, minusnum, newnum] = [isla[b], color, 0]
          plusval = [num[isla[b]] - dif, num[isla[b]]]
          minusval = [dif, 0]
      else:
          [plusnum, minusnum, newnum] = [0, 0, 0]
      # print("bri[i]",bri[i])
      # print("isla",isla)
      # print("crus",crus)
      # print("num",num)
  
      if i == 0:
          total = 0
      else:
          total = score[-1]
      if newnum != 0:
          total += 1
      if plusnum != 0:
          total += (plusval[1] * (plusval[1] - 1)) // 2
          total -= (plusval[0] * (plusval[0] - 1)) // 2
      if minusnum != 0:
          total += (minusval[1] * (minusval[1] - 1)) // 2
          total -= (minusval[0] * (minusval[0] - 1)) // 2
      score.append(total)
      # print("total",total)
      # print()
  
  
  score.reverse()
  for i in range(len(score)):
      score[i] = (n * (n - 1)) // 2 - score[i]
  score.append((n * (n - 1)) // 2)
  score = score[1:]
  for i in range(len(score)):
      print(score[i])
  
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"}]