Problem:
Score : 700 points

Problem Statement

You are given an integer N.
Build an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions:

The graph is simple and connected.

There exists an integer S such that, for every vertex, the sum of the indices of the vertices adjacent to that vertex is S.

It can be proved that at least one such graph exists under the constraints of this problem.

Constraints

All values in input are integers.

3 \leq N \leq 100

Input

Input is given from Standard Input in the following format:

N

Output

In the first line, print the number of edges, M, in the graph you made. In the i-th of the following M lines, print two integers a_i and b_i, representing the endpoints of the i-th edge.

The output will be judged correct if the graph satisfies the conditions.

Sample Input 1

3

Sample Output 1

2
1 3
2 3

For every vertex, the sum of the indices of the vertices adjacent to that vertex is 3.

Solution in Common Lisp (SBCL 1.1.14) (judge verdict: Accepted)

(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 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 map-graph (n)
;;   (let ((sum (* n n))
;;         (table (make-array n :element-type 'uint32 :initial-element 0)))
;;     (dotimes (mask (expt 2 sum))
;;       (fill table 0)
;;       (dotimes (k sum)
;;         (let* ((j (mod k n))
;;                (i (floor k n)))
;;           (when (and (/= j i)
;;                      (logbitp k mask))
;;             (incf (aref table i) (1+ j)))))
;;       (when (loop for i from 1 below n
;;                   always (= (aref table i) (aref table (- i 1))))
;;         (format t "~D:~%" (aref table 0))
;;         (dotimes (i n)
;;           (dotimes (j n (terpri))
;;             (princ (ldb (byte 1 (+ (* n i) j)) mask))))))))

;; (defun %test (n &optional (sample 1000))
;;   (let ((adja (make-array (list n n) :element-type 'bit :initial-element 0))
;;         (table (make-array n :element-type 'uint32 :initial-element 0)))
;;     (dotimes (i sample)
;;       (fill table 0)
;;       (fill (array-storage-vector adja) 0)
;;       (dotimes (i n)
;;         (loop for j from (1+ i) below n
;;               do (when (> (random 1.0) 0.5)
;;                    (setf (aref adja i j) 1
;;                          (aref adja j i) 1)
;;                    (incf (aref table i) (+ 1 j))
;;                    (incf (aref table j) (+ 1 i))))
;;         (when (loop for i from 1 below n
;;                     always (and (not (zerop (aref table i)))
;;                                 (= (aref table i) (aref table (- i 1)))))
;;           (format t "~D:~%" (aref table 0))
;;           #>adja)))))

;; ADJA => #2A((0 1 1 1 1 0 1)
;;             (1 0 1 1 0 1 1)
;;             (1 1 0 0 1 1 1)
;;             (1 1 0 0 1 1 1)
;;             (1 0 1 1 0 1 1)
;;             (0 1 1 1 1 0 1)
;;             (1 1 1 1 1 1 0))
(defun main ()
  (let* ((n (read))
         (adja (make-array n :element-type 'bit :initial-element 0))
         res)
    (if (evenp n)
        (progn
          (dotimes (i n)
            (loop for j from (1+ i) below n
                  do (unless (= (+ i j) (- n 1))
                       (push (cons (1+ i) (1+ j)) res)))))
        (progn
          (dotimes (i n)
            (loop for j from (1+ i) below (- n 1)
                  do (unless (= (+ i j) (- n 2))
                       (push (cons (1+ i) (1+ j)) res))))
          (dotimes (i (- n 1))
            (push (cons (1+ i) n) res))))
    (println (length res))
          (dolist (pair res)
            (format t "~D ~D~%" (car pair) (cdr pair)))))

#-swank(main)