(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 buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (terminate-char #\Space))
  "Note that the returned string will be reused."
  (let ((buffer (gensym))
        (character (gensym))
        (idx (gensym)))
    `(let ((,buffer (load-time-value (make-string ,buffer-size
                                                  :element-type 'base-char))))
       (declare (simple-base-string ,buffer))
       (loop for ,character of-type base-char =
                #-swank (code-char (read-byte ,in nil #.(char-code #\Newline)))
                #+swank (read-char ,in nil #\Newline)
             for ,idx from 0
             until (char= ,character #\Newline)
             do (setf (schar ,buffer ,idx) ,character)
             finally (when (< ,idx ,buffer-size)
                       (setf (schar ,buffer ,idx) ,terminate-char))
                     (return (values ,buffer ,idx))))))

(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 (disjoint-set
            (:constructor make-disjoint-set
                (size &aux (parents (make-array size :element-type 'fixnum :initial-element -1))))
            (:conc-name ds-))
  (parents nil :type (simple-array fixnum (*))))

(declaim (ftype (function * (values non-negative-fixnum &optional)) ds-root))
(defun ds-root (x disjoint-set)
  "Returns the root of X."
  (declare #.OPT
           (non-negative-fixnum x))
  (let ((parents (ds-parents disjoint-set)))
    (if (< (aref parents x) 0)
        x
        (setf (aref parents x)
              (ds-root (aref parents x) disjoint-set)))))

(declaim (inline ds-unite!))
(defun ds-unite! (x1 x2 disjoint-set)
  "Unites X1 and X2 destructively."
  (let ((root1 (ds-root x1 disjoint-set))
        (root2 (ds-root x2 disjoint-set)))
    (unless (= root1 root2)
      (let ((parents (ds-parents disjoint-set)))
        ;; guarantees the size of root1 >= the size of root2
        (when (> (aref parents root1) (aref parents root2))
          (rotatef root1 root2))
        (incf (aref parents root1) (aref parents root2))
        (setf (aref parents root2) root1)))))

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

(declaim (inline ds-size))
(defun ds-size (x disjoint-set)
  (- (aref (ds-parents disjoint-set)
           (ds-root x disjoint-set))))

(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 ()
  (declare #.OPT)
  (let* ((n (read))
         (m (read))
         (as (make-array m :element-type 'uint31))
         (bs (make-array m :element-type 'uint31))
         (tree (make-disjoint-set n))
         (inconvs (make-array (1+ m) :element-type 'fixnum))
         (out (make-string-output-stream :element-type 'base-char)))
    (declare (uint31 n m))
    (setf (aref inconvs m) (floor (* n (- n 1)) 2))
    (dotimes (i m)
      (split-ints-bind (a b) (buffered-read-line 13)
        (declare (uint31 a b))
        (setf (aref as i) (- a 1))
        (setf (aref bs i) (- b 1))))
    (loop for i from (1- m) downto 0
          do (let* ((a (aref as i))
                    (b (aref bs i)))
               (if (ds-connected-p a b tree)
                   (setf (aref inconvs i)
                         (aref inconvs (1+ i)))
                   (setf (aref inconvs i)
                         (- (aref inconvs (1+ i))
                            (* (the uint31 (ds-size a tree))
                               (the uint31 (ds-size b tree))))))
               (ds-unite! a b tree)))
    (loop for i from 1 to m
          do (println (aref inconvs i) out))
    (write-string (get-output-stream-string out))))

#-swank(main)


Measured memory_bytes: 27872