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 UnionFind:
      def __init__(self, size: int):
          self.__root = [-1 for _ in range(size)]
          self.__size = [1 for _ in range(size)]
  
      def find(self, v: int) -> int:
          if self.__root[v] == -1:
              return v
          return self.find(self.__root[v])
  
      def size(self, v: int) -> int:
          root = self.find(v)
          return self.__size[root]
  
      def unite(self, u: int, v: int):
          ur, vr = self.find(u), self.find(v)
          if ur > vr:
              ur, vr = vr, ur
  
          self.__size[ur] += self.__size[vr]
          self.__root[vr] = ur
  
      def connected(self, u: int, v: int):
          return self.find(u) == self.find(v)
  
      def print(self):
          print("-" * 5 + " root " + "-" * 5)
          print(self.__root)
          print("-" * 5 + " size " + "-" * 5)
          print(self.__size)
  
  
  def decayed_bridges(N: int, M: int, edges: list) -> list:
      ret = [0 for _ in range(M + 1)]
      uf = UnionFind(N + 1)
  
      m = M
      ret[m] = N * (N - 1) // 2
      m -= 1
      for u, v in reversed(edges):
          if uf.connected(u, v):
              ret[m] = ret[m + 1]
          else:
              n1, n2 = uf.size(u), uf.size(v)
              ret[m] = ret[m + 1] - n1 * n2
              uf.unite(u, v)
  
          m -= 1
  
      return ret
  
  
  if __name__ == "__main__":
      N, M = [int(s) for s in input().split()]
      edges = []
      for _ in range(M):
          a, b = [int(s) for s in input().split()]
          edges.append((a, b))
  
      answers = decayed_bridges(N, M, edges)
  
      for a in answers:
          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"}]