(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(defmacro split-ints-bind (vars string &body body)
  (let ((position (gensym))
        (s (gensym)))
    (labels ((expand (vars &optional init-pos)
               (if (null vars)
                   body
                   `((multiple-value-bind (,(car vars) ,position)
                         (parse-integer ,s :start ,(or init-pos position)
                                           :junk-allowed t)
                       ,@(when (null (cdr vars)) `((declare (ignore ,position))))
                       ,@(expand (cdr vars)))))))
      `(let ((,s ,string))
         (declare (string ,s))
         ,@(expand vars 0)))))



(deftype non-negative-fixnum () '(integer 0 #.most-positive-fixnum))

(defstruct (union-find
            (:constructor make-union-find
                (size &aux (parents (let ((seq (make-array size :element-type 'non-negative-fixnum)))
                                      (dotimes (i size seq) (setf (aref seq i) i))))
                           (ranks (make-array size :element-type 'non-negative-fixnum
                                                   :initial-element 0))
                           (sizes (make-array size :element-type 'non-negative-fixnum
                                                   :initial-element 1))))
            (:conc-name uf-))
  (parents nil :type (simple-array non-negative-fixnum (*)))
  (ranks nil :type (simple-array non-negative-fixnum (*)))
  (sizes nil :type (simple-array non-negative-fixnum (*))))

(declaim (ftype (function * (values non-negative-fixnum &optional)) uf-root))
(defun uf-root (x uf-tree)
  "Returns the root of X."
  (declare (optimize (speed 3))
           (non-negative-fixnum x))
  (let ((parents (uf-parents uf-tree)))
    (if (= x (aref parents x))
        x
        (setf (aref parents x)
              (uf-root (aref parents x) uf-tree)))))

(declaim (inline uf-unite!))
(defun uf-unite! (x1 x2 uf-tree)
  "Unites X1 and X2 destructively."
  (let ((root1 (uf-root x1 uf-tree))
        (root2 (uf-root x2 uf-tree)))
    (unless (= root1 root2)
      (let ((parents (uf-parents uf-tree))
            (ranks (uf-ranks uf-tree)))
        (when (< (aref ranks root1) (aref ranks root2))
          (rotatef root1 root2))
        ;; (rank root1) >= (rank root2)
        (setf (aref parents root2) root1)
        (incf (aref (uf-sizes uf-tree) root1) (aref (uf-sizes uf-tree) root2))
        (when (= (aref ranks root1) (aref ranks root2))
          (incf (aref ranks root1)))))))

(declaim (inline uf-connected-p))
(defun uf-connected-p (x1 x2 uf-tree)
  "Checks if X1 and X2 have the same root."
  (= (uf-root x1 uf-tree) (uf-root x2 uf-tree)))

(declaim (inline uf-size))
(defun uf-size (x uf-tree)
  (aref (uf-sizes uf-tree)
        (uf-root x uf-tree)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

(defconstant +mod+ 1000000007)

;; Hauptteil

(defun main ()
  (let* ((n (read))
         (m (read))
         (as (make-array m :element-type 'uint32))
         (bs (make-array m :element-type 'uint32))
         (tree (make-union-find n))
         (inconvs (make-array (1+ m) :element-type 'fixnum)))
    (setf (aref inconvs m) (floor (* n (- n 1)) 2))
    (dotimes (i m)
      (split-ints-bind (a b) (read-line)
        (decf a)
        (decf b)
        (setf (aref as i) a)
        (setf (aref bs i) b)))
    (loop for i from (1- m) downto 0
          do (let* ((a (aref as i))
                    (b (aref bs i))
                    (prev-size-a (uf-size a tree))
                    (prev-size-b (uf-size b tree))
                    (delta (* prev-size-a prev-size-b)))
               (if (uf-connected-p a b tree)
                   (setf (aref inconvs i)
                         (aref inconvs (1+ i)))
                   (progn (setf (aref inconvs i)
                                (- (aref inconvs (1+ i)) delta))
                          (uf-unite! a b tree)))))
    (loop for i from 1 to m
          do (println (aref inconvs i)))))

#-swank(main)


Measured memory_bytes: 56936