import sys

input = sys.stdin.readline


class UnionFind:
    """Union Find class.

    "Path compression" and "Union by rank" are used.

    References:
        <https://en.wikipedia.org/wiki/Disjoint-set_data_structure>
    """

    def __init__(self, N):
        self.N = N
        self.__make_set()

    def __make_set(self):
        self._parent = list(range(self.N + 1))
        self._rank = [0] * (self.N + 1)
        self._size = [1] * (self.N + 1)

    def find(self, x):
        if self._parent[x] != x:
            self._parent[x] = self.find(self._parent[x])
        return self._parent[x]

    def union(self, x, y):
        x_root = self.find(x)
        y_root = self.find(y)

        if x_root == y_root:
            return

        x_rank = self._rank[x_root]
        y_rank = self._rank[y_root]
        if x_rank > y_rank:
            self._parent[y_root] = x_root
            self._size[x_root] += self._size[y_root]
        elif x_rank < y_rank:
            self._parent[x_root] = y_root
            self._size[y_root] += self._size[x_root]
        else:
            self._parent[y_root] = x_root
            self._rank[x_root] += 1
            self._size[x_root] += self._size[y_root]

    def same_set(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return self._size[self.find(x)]


def main():
    N, M = map(int, input().split())
    A = [0] * M
    B = [0] * M
    for i in range(M):
        A[i], B[i] = map(int, input().split())

    uf = UnionFind(N)
    ans = [0] * M
    ans[-1] = N * (N - 1) // 2
    for i in reversed(range(M - 1)):
        a, b = A[i + 1], B[i + 1]
        if uf.same_set(a, b):
            ans[i] = ans[i + 1]
        else:
            ans[i] = ans[i + 1] - uf.size(a) * uf.size(b)
        uf.union(a, b)

    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main() import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline class UnionFind:
    """Union Find class.

    "Path compression" and "Union by rank" are used.

    References:
        <https://en.wikipedia.org/wiki/Disjoint-set_data_structure>
    """

    def __init__(self, N):
        self.N = N
        self.__make_set()

    def __make_set(self):
        self._parent = list(range(self.N + 1))
        self._rank = [0] * (self.N + 1)
        self._size = [1] * (self.N + 1)

    def find(self, x):
        if self._parent[x] != x:
            self._parent[x] = self.find(self._parent[x])
        return self._parent[x]

    def union(self, x, y):
        x_root = self.find(x)
        y_root = self.find(y)

        if x_root == y_root:
            return

        x_rank = self._rank[x_root]
        y_rank = self._rank[y_root]
        if x_rank > y_rank:
            self._parent[y_root] = x_root
            self._size[x_root] += self._size[y_root]
        elif x_rank < y_rank:
            self._parent[x_root] = y_root
            self._size[y_root] += self._size[x_root]
        else:
            self._parent[y_root] = x_root
            self._rank[x_root] += 1
            self._size[x_root] += self._size[y_root]

    def same_set(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return self._size[self.find(x)] UnionFind """Union Find class.

    "Path compression" and "Union by rank" are used.

    References:
        <https://en.wikipedia.org/wiki/Disjoint-set_data_structure>
    """ def __init__(self, N):
        self.N = N
        self.__make_set()

     __init__ self.N = N self.N self N N self.__make_set() self.__make_set self __make_set self self N N def __make_set(self):
        self._parent = list(range(self.N + 1))
        self._rank = [0] * (self.N + 1)
        self._size = [1] * (self.N + 1)

     __make_set self._parent = list(range(self.N + 1)) self._parent self _parent list(range(self.N + 1)) list range(self.N + 1) range self.N + 1 self.N self N 1 self._rank = [0] * (self.N + 1) self._rank self _rank [0] * (self.N + 1) [0] 0 self.N + 1 self.N self N 1 self._size = [1] * (self.N + 1) self._size self _size [1] * (self.N + 1) [1] 1 self.N + 1 self.N self N 1 self self def find(self, x):
        if self._parent[x] != x:
            self._parent[x] = self.find(self._parent[x])
        return self._parent[x]

     find if self._parent[x] != x:
            self._parent[x] = self.find(self._parent[x])
         self._parent[x] != x self._parent[x] self._parent self _parent x x self._parent[x] = self.find(self._parent[x]) self._parent[x] self._parent self _parent x self.find(self._parent[x]) self.find self find self._parent[x] self._parent self _parent x return self._parent[x] self._parent[x] self._parent self _parent x self self x x def union(self, x, y):
        x_root = self.find(x)
        y_root = self.find(y)

        if x_root == y_root:
            return

        x_rank = self._rank[x_root]
        y_rank = self._rank[y_root]
        if x_rank > y_rank:
            self._parent[y_root] = x_root
            self._size[x_root] += self._size[y_root]
        elif x_rank < y_rank:
            self._parent[x_root] = y_root
            self._size[y_root] += self._size[x_root]
        else:
            self._parent[y_root] = x_root
            self._rank[x_root] += 1
            self._size[x_root] += self._size[y_root]

     union x_root = self.find(x) x_root self.find(x) self.find self find x y_root = self.find(y) y_root self.find(y) self.find self find y if x_root == y_root:
            return

         x_root == y_root x_root y_root return x_rank = self._rank[x_root] x_rank self._rank[x_root] self._rank self _rank x_root y_rank = self._rank[y_root] y_rank self._rank[y_root] self._rank self _rank y_root if x_rank > y_rank:
            self._parent[y_root] = x_root
            self._size[x_root] += self._size[y_root]
        elif x_rank < y_rank:
            self._parent[x_root] = y_root
            self._size[y_root] += self._size[x_root]
        else:
            self._parent[y_root] = x_root
            self._rank[x_root] += 1
            self._size[x_root] += self._size[y_root]

     x_rank > y_rank x_rank y_rank self._parent[y_root] = x_root self._parent[y_root] self._parent self _parent y_root x_root self._size[x_root] += self._size[y_root] self._size[x_root] self._size self _size x_root self._size[y_root] self._size self _size y_root elif x_rank < y_rank:
            self._parent[x_root] = y_root
            self._size[y_root] += self._size[x_root]
         x_rank < y_rank x_rank y_rank self._parent[x_root] = y_root self._parent[x_root] self._parent self _parent x_root y_root self._size[y_root] += self._size[x_root] self._size[y_root] self._size self _size y_root self._size[x_root] self._size self _size x_root self._parent[y_root] = x_root self._parent[y_root] self._parent self _parent y_root x_root self._rank[x_root] += 1 self._rank[x_root] self._rank self _rank x_root 1 self._size[x_root] += self._size[y_root] self._size[x_root] self._size self _size x_root self._size[y_root] self._size self _size y_root self self x x y y def same_set(self, x, y):
        return self.find(x) == self.find(y)

     same_set return self.find(x) == self.find(y) self.find(x) == self.find(y) self.find(x) self.find self find x self.find(y) self.find self find y self self x x y y def size(self, x):
        return self._size[self.find(x)] size return self._size[self.find(x)] self._size[self.find(x)] self._size self _size self.find(x) self.find self find x self self x x def main():
    N, M = map(int, input().split())
    A = [0] * M
    B = [0] * M
    for i in range(M):
        A[i], B[i] = map(int, input().split())

    uf = UnionFind(N)
    ans = [0] * M
    ans[-1] = N * (N - 1) // 2
    for i in reversed(range(M - 1)):
        a, b = A[i + 1], B[i + 1]
        if uf.same_set(a, b):
            ans[i] = ans[i + 1]
        else:
            ans[i] = ans[i + 1] - uf.size(a) * uf.size(b)
        uf.union(a, b)

    print("\n".join(map(str, ans))) main N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M A = [0] * M A [0] * M [0] 0 M B = [0] * M B [0] * M [0] 0 M for i in range(M):
        A[i], B[i] = map(int, input().split())

     i range(M) range M A[i], B[i] = map(int, input().split()) A[i] A i map(int, input().split()) map int input().split() ().split () input split B[i] B i uf = UnionFind(N) uf UnionFind(N) UnionFind N ans = [0] * M ans [0] * M [0] 0 M ans[-1] = N * (N - 1) // 2 ans[-1] ans -1 N * (N - 1) // 2 N * (N - 1) N N - 1 N 1 2 for i in reversed(range(M - 1)):
        a, b = A[i + 1], B[i + 1]
        if uf.same_set(a, b):
            ans[i] = ans[i + 1]
        else:
            ans[i] = ans[i + 1] - uf.size(a) * uf.size(b)
        uf.union(a, b)

     i reversed(range(M - 1)) reversed range(M - 1) range M - 1 M 1 a, b = A[i + 1], B[i + 1] a A[i + 1] A i + 1 i 1 b B[i + 1] B i + 1 i 1 if uf.same_set(a, b):
            ans[i] = ans[i + 1]
        else:
            ans[i] = ans[i + 1] - uf.size(a) * uf.size(b)
         uf.same_set(a, b) uf.same_set uf same_set a b ans[i] = ans[i + 1] ans[i] ans i ans[i + 1] ans i + 1 i 1 ans[i] = ans[i + 1] - uf.size(a) * uf.size(b) ans[i] ans i ans[i + 1] - uf.size(a) * uf.size(b) ans[i + 1] ans i + 1 i 1 uf.size(a) * uf.size(b) uf.size(a) uf.size uf size a uf.size(b) uf.size uf size b uf.union(a, b) uf.union uf union a b print("\n".join(map(str, ans))) print "\n".join(map(str, ans)) "\n".join "\n" join map(str, ans) map str ans if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    N, M = map(int, input().split())
    A = [0] * M
    B = [0] * M
    for i in range(M):
        A[i], B[i] = map(int, input().split())

    uf = UnionFind(N)
    ans = [0] * M
    ans[-1] = N * (N - 1) // 2
    for i in reversed(range(M - 1)):
        a, b = A[i + 1], B[i + 1]
        if uf.same_set(a, b):
            ans[i] = ans[i + 1]
        else:
            ans[i] = ans[i + 1] - uf.size(a) * uf.size(b)
        uf.union(a, b)

    print("\n".join(map(str, ans))) def main():
    N, M = map(int, input().split())
    A = [0] * M
    B = [0] * M
    for i in range(M):
        A[i], B[i] = map(int, input().split())

    uf = UnionFind(N)
    ans = [0] * M
    ans[-1] = N * (N - 1) // 2
    for i in reversed(range(M - 1)):
        a, b = A[i + 1], B[i + 1]
        if uf.same_set(a, b):
            ans[i] = ans[i + 1]
        else:
            ans[i] = ans[i + 1] - uf.size(a) * uf.size(b)
        uf.union(a, b)

    print("\n".join(map(str, ans))) main class UnionFind:
    """Union Find class.

    "Path compression" and "Union by rank" are used.

    References:
        <https://en.wikipedia.org/wiki/Disjoint-set_data_structure>
    """

    def __init__(self, N):
        self.N = N
        self.__make_set()

    def __make_set(self):
        self._parent = list(range(self.N + 1))
        self._rank = [0] * (self.N + 1)
        self._size = [1] * (self.N + 1)

    def find(self, x):
        if self._parent[x] != x:
            self._parent[x] = self.find(self._parent[x])
        return self._parent[x]

    def union(self, x, y):
        x_root = self.find(x)
        y_root = self.find(y)

        if x_root == y_root:
            return

        x_rank = self._rank[x_root]
        y_rank = self._rank[y_root]
        if x_rank > y_rank:
            self._parent[y_root] = x_root
            self._size[x_root] += self._size[y_root]
        elif x_rank < y_rank:
            self._parent[x_root] = y_root
            self._size[y_root] += self._size[x_root]
        else:
            self._parent[y_root] = x_root
            self._rank[x_root] += 1
            self._size[x_root] += self._size[y_root]

    def same_set(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return self._size[self.find(x)] class UnionFind:
    """Union Find class.

    "Path compression" and "Union by rank" are used.

    References:
        <https://en.wikipedia.org/wiki/Disjoint-set_data_structure>
    """

    def __init__(self, N):
        self.N = N
        self.__make_set()

    def __make_set(self):
        self._parent = list(range(self.N + 1))
        self._rank = [0] * (self.N + 1)
        self._size = [1] * (self.N + 1)

    def find(self, x):
        if self._parent[x] != x:
            self._parent[x] = self.find(self._parent[x])
        return self._parent[x]

    def union(self, x, y):
        x_root = self.find(x)
        y_root = self.find(y)

        if x_root == y_root:
            return

        x_rank = self._rank[x_root]
        y_rank = self._rank[y_root]
        if x_rank > y_rank:
            self._parent[y_root] = x_root
            self._size[x_root] += self._size[y_root]
        elif x_rank < y_rank:
            self._parent[x_root] = y_root
            self._size[y_root] += self._size[x_root]
        else:
            self._parent[y_root] = x_root
            self._rank[x_root] += 1
            self._size[x_root] += self._size[y_root]

    def same_set(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return self._size[self.find(x)] UnionFind input = sys.stdin.readline sys.stdin.readline input
import sys

input = sys.stdin.readline


class UnionFind:
    """Union Find class.

    "Path compression" and "Union by rank" are used.

    References:
        <https://en.wikipedia.org/wiki/Disjoint-set_data_structure>
    """

    def __init__(self, N):
        self.N = N
        self.__make_set()

    def __make_set(self):
        self._parent = list(range(self.N + 1))
        self._rank = [0] * (self.N + 1)
        self._size = [1] * (self.N + 1)

    def find(self, x):
        if self._parent[x] != x:
            self._parent[x] = self.find(self._parent[x])
        return self._parent[x]

    def union(self, x, y):
        x_root = self.find(x)
        y_root = self.find(y)

        if x_root == y_root:
            return

        x_rank = self._rank[x_root]
        y_rank = self._rank[y_root]
        if x_rank > y_rank:
            self._parent[y_root] = x_root
            self._size[x_root] += self._size[y_root]
        elif x_rank < y_rank:
            self._parent[x_root] = y_root
            self._size[y_root] += self._size[x_root]
        else:
            self._parent[y_root] = x_root
            self._rank[x_root] += 1
            self._size[x_root] += self._size[y_root]

    def same_set(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return self._size[self.find(x)]


def main():
    N, M = map(int, input().split())
    A = [0] * M
    B = [0] * M
    for i in range(M):
        A[i], B[i] = map(int, input().split())

    uf = UnionFind(N)
    ans = [0] * M
    ans[-1] = N * (N - 1) // 2
    for i in reversed(range(M - 1)):
        a, b = A[i + 1], B[i + 1]
        if uf.same_set(a, b):
            ans[i] = ans[i + 1]
        else:
            ans[i] = ans[i + 1] - uf.size(a) * uf.size(b)
        uf.union(a, b)

    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()
