Language: C++

;; -*- coding: utf-8 -*-
(eval-when (:compile-toplevel :load-toplevel :execute)
  (sb-int:defconstant-eqx OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0))
    #'equal)
  #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)
  #-swank (set-dispatch-macro-character
           #\# #\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)
#-swank (disable-debugger) ; for CS Academy

;; BEGIN_INSERTED_CONTENTS
(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(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)

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1 (princ obj stream) (terpri stream))))

(defconstant +mod+ 1000000007)

;;;
;;; Body
;;;

(defun main ()
  (let* ((n (read)))
    (println
     (loop for x from 1 to (- n 1)
           count (and (< x (- n x)))))))

#-swank (main)

;;;
;;; Test and benchmark
;;;

#+swank
(defun io-equal (in-string out-string &key (function #'main) (test #'equal))
  "Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if
the string output to *STANDARD-OUTPUT* is equal to OUT-STRING."
  (labels ((ensure-last-lf (s)
             (if (eql (uiop:last-char s) #\Linefeed)
                 s
                 (uiop:strcat s uiop:+lf+))))
    (funcall test
             (ensure-last-lf out-string)
             (with-output-to-string (out)
               (let ((*standard-output* out))
                 (with-input-from-string (*standard-input* (ensure-last-lf in-string))
                   (funcall function)))))))

#+swank
(defun get-clipbrd ()
  (with-output-to-string (out)
    (run-program "C:/msys64/usr/bin/cat.exe" '("/dev/clipboard") :output out)))

#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))
#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* "test.dat" *this-pathname*))

#+swank
(defun run (&optional thing (out *standard-output*))
  "THING := null | string | symbol | pathname

null: run #'MAIN using the text on clipboard as input.
string: run #'MAIN using the string as input.
symbol: alias of FIVEAM:RUN!.
pathname: run #'MAIN using the text file as input."
  (let ((*standard-output* out))
    (etypecase thing
      (null
       (with-input-from-string (*standard-input* (delete #\Return (get-clipbrd)))
         (main)))
      (string
       (with-input-from-string (*standard-input* (delete #\Return thing))
         (main)))
      (symbol (5am:run! thing))
      (pathname
       (with-open-file (*standard-input* thing)
         (main))))))

#+swank
(defun gen-dat ()
  (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)
    (format out "")))

#+swank
(defun bench (&optional (out (make-broadcast-stream)))
  (time (run *dat-pathname* out)))

;; To run: (5am:run! :sample)
#+swank
(it.bese.fiveam:test :sample
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "4
"
    "1
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "999999
"
    "499999
")))


Compiler output:
a.cc:4:6: error: invalid preprocessing directive #+
    4 |     #+swank '(optimize (speed 3) (safety 2))
      |      ^
a.cc:4:13: warning: missing terminating ' character
    4 |     #+swank '(optimize (speed 3) (safety 2))
      |             ^
a.cc:5:6: error: invalid preprocessing directive #-
    5 |     #-swank '(optimize (speed 3) (safety 0) (debug 0))
      |      ^
a.cc:5:13: warning: missing terminating ' character
    5 |     #-swank '(optimize (speed 3) (safety 0) (debug 0))
      |             ^
a.cc:6:6: warning: missing terminating ' character
    6 |     #'equal)
      |      ^
a.cc:6:6: error: invalid preprocessing directive #'equal)
    6 |     #'equal)
      |      ^~~~~~~
a.cc:7:4: error: invalid preprocessing directive #+
    7 |   #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)
      |    ^
a.cc:7:25: warning: missing terminating ' character
    7 |   #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)
      |                         ^
a.cc:8:4: error: invalid preprocessing directive #-
    8 |   #-swank (set-dispatch-macro-character
      |    ^
a.cc:9:13: error: invalid preprocessing directive #\
    9 |            #\# #\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))
      |             ^
a.cc:10:2: error: invalid preprocessing directive #+
   10 | #+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)
      |  ^
a.cc:11:2: error: invalid preprocessing directive #-
   11 | #-swank (disable-debugger) ; for CS Academy
      |  ^
a.cc:15:4: error: invalid preprocessing directive #+
   15 |   #+swank
      |    ^
a.cc:17:7: error: stray '`' in program
   17 |       `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      |       ^
a.cc:17:44: warning: missing terminating ' character
   17 |       `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      |                                            ^
a.cc:17:44: error: missing terminating ' character
   17 |       `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      |                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:18:7: error: stray '`' in program
   18 |       `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
      |       ^
a.cc:18:44: warning: missing terminating ' character
   18 |       `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
      |                                            ^
a.cc:18:44: error: missing terminating ' character
   18 |       `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
      |                                            ^~~~~~~~~~~~~~~~~~~~~
a.cc:19:4: error: invalid preprocessing directive #-
   19 |   #-swank (declare (ignore forms)))
      |    ^
a.cc:22:3: error: stray '`' in program
   22 |   `(progn
      |   ^
a.cc:23:7: error: stray '@' in program
   23 |      ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
      |       ^
a.cc:23:28: error: stray '`' in program
   23 |      ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
      |                            ^
a.cc:23:75: warning: missing terminating ' character
   23 |      ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
      |                                                                           ^
a.cc:23:75: error: missing terminating ' character
   23 |      ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
      |                                                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:24:7: error: stray '@' in program
   24 |      ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
      |       ^
a.cc:24:28: error: stray '`' in program
   24 |      ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
      |                            ^
a.cc:24:74: warning: missing terminating ' character
   24 |      ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
      |                                                                          ^
a.cc:24:74: error: missing terminating ' character
   24 |      ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
      |                                                                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:29:38: warning: missing terminating ' character
   29 |   (let ((*read-default-float-format* 'double-float))
      |                                      ^
a.cc:29:38: error: missing terminating ' character
   29 |   (let ((*read-default-float-format* 'double-float))
      |                                      ^~~~~~~~~~~~~~~
a.cc:44:2: error: invalid preprocessing directive #-
   44 | #-swank (main)
      |  ^
a.cc:50:2: error: invalid preprocessing directive #+
   50 | #+swank
      |  ^
a.cc:51:54: error: stray '#' in program
   51 | (defun io-equal (in-string out-string &key (function #'main) (test #'equal))
      |                                                      ^
a.cc:51:55: warning: multi-character literal with 13 characters exceeds 'int' size of 4 bytes
   51 | (defun io-equal (in-string out-string &key (function #'main) (test #'equal))
      |                                                       ^~~~~~~~~~~~~~~~~~~~
a.cc:52:3: warning: missing terminating " character
   52 |   "Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if
      |   ^
a.cc:52:3: error: missing terminating " character
   52 |   "Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:53:63: warning: missing terminating " character
   53 | the string output to *STANDARD-OUTPUT* is equal to OUT-STRING."
      |                                                               ^
a.cc:53:63: error: missing terminating " character
a.cc:55:42: error: stray '#' in program
   55 |              (if (eql (uiop:last-char s) #\Linefeed)
      |                                          ^
a.cc:55:43: error: stray '\' in program
   55 |              (if (eql (uiop:last-char s) #\Linefeed)
      |                                           ^
a.cc:65:2: error: invalid preprocessing directive #+
   65 | #+swank
      |  ^
a.cc:68:46: warning: missing terminating ' character
   68 |     (run-program "C:/msys64/usr/bin/cat.exe" '("/dev/clipboard") :output out)))
      |                                              ^
a.cc:68:46: error: missing terminating ' character
   68 |     (run-program "C:/msys64/usr/bin/cat.exe" '("/dev/clipboard") :output out)))
      |                                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:70:2: error: invalid preprocessing directive #+
   70 | #+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))
      |  ^
a.cc:71:2: error: invalid preprocessing directive #+
   71 | #+swank (defparameter *dat-pathname* (uiop:merge-pathnames* "test.dat" *this-pathname*))
      |  ^
a.cc:73:2: error: invalid preprocessing directive #+
   73 | #+swank
      |  ^
a.cc:75:3: warning: missing terminating " character
   75 |   "THING := null | string | symbol | pathname
      |   ^
a.cc:75:3: error: missing terminating " character
   75 |   "THING := null | string | symbol | pathname
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:77:11: error: stray '#' in program
   77 | null: run #'MAIN using the text on clipboard as input.
      |           ^
a.cc:77:12: warning: missing terminating ' character
   77 | null: run #'MAIN using the text on clipboard as input.
      |            ^
a.cc:77:12: error: missing terminating ' character
   77 | null: run #'MAIN using the text on clipboard as input.
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:78:13: error: stray '#' in program
   78 | string: run #'MAIN using the string as input.
      |             ^
a.cc:78:14: warning: missing terminating ' character
   78 | string: run #'MAIN using the string as input.
      |              ^
a.cc:78:14: error: missing terminating ' character
   78 | string: run #'MAIN using the string as input.
      |              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:80:15: error: stray '#' in program
   80 | pathname: run #'MAIN using the text file as input."
      |               ^
a.cc:80:16: warning: missing terminating ' character
   80 | pathname: run #'MAIN using the text file as input."
      |                ^
a.cc:80:16: error: missing terminating ' character
   80 | pathname: run #'MAIN using the text file as input."
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:84:58: error: stray '#' in program
   84 |        (with-input-from-string (*standard-input* (delete #\Return (get-clipbrd)))
      |                                                          ^
a.cc:84:59: error: stray '\' in program
   84 |        (with-input-from-string (*standard-input* (delete #\Return (get-clipbrd)))
      |                                                           ^
a.cc:87:58: error: stray '#' in program
   87 |        (with-input-from-string (*standard-input* (delete #\Return thing))
      |                                                          ^
a.cc:87:59: error: stray '\' in program
   87 |        (with-input-from-string (*standard-input* (delete #\Return thing))
      |                                                           ^
a.cc:94:2: error: invalid preprocessing directive #+
   94 | #+swank
      |  ^
a.cc:99:2: error: invalid preprocessing directive #+
   99 | #+swank
      |  ^
a.cc:104:2: error: invalid preprocessing directive #+
  104 | #+swank
      |  ^
a.cc:107:32: warning: missing terminating " character
  107 |    (common-lisp-user::io-equal "4
      |                                ^
a.cc:107:32: error: missing terminating " character
  107 |    (common-lisp-user::io-equal "4
      |                                ^~
a.cc:108:1: warning: missing terminating " character
  108 | "
      | ^
a.cc:108