;; C - Guess The Number

(defun solve (n sc)
  (let ((buf (make-array n :initial-element nil)))
    (loop for (s . c) in sc
          for prev = (aref buf (1- s))
       do (setf (aref buf (1- s))
                (if (and prev (/= prev c)) 'error c)))
    (if (or (find 'error buf) (eql (aref buf 0) 0))
        -1
        (loop for i below n
          unless (aref buf i)
              do (setf (aref buf i) (if (and (= i 0) (> n 1)) 1 0))
          finally (return (map 'string #'digit-char buf))))))

(let* ((n  (read))
       (m  (read))
       (sc (loop repeat m collect (cons (read) (read)))))
  (princ (solve n sc)))


;; C - Guess The Number

(defun solve (n sc)
  (loop for i from 0 below (expt 10 n)
        for digits = (map 'vector #'digit-char-p (princ-to-string i))
     when (and (= (length digits) n)
               (zerop
                 (loop for (s . c) in sc
                   count (not (eql c (aref digits (1- s)))))))
     do (return i)
     finally (return -1)))

(let* ((n  (read))
       (m  (read))
       (sc (loop repeat m collect (cons (read) (read)))))
  (princ (solve n sc)))

Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.

Score : 300 points

Problem Statement

If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print -1.

The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.)

The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right)

Constraints

All values in input are integers.

1 \leq N \leq 3

0 \leq M \leq 5

1 \leq s_i \leq N

0 \leq c_i \leq 9

Input

Input is given from Standard Input in the following format:

N M
s_1 c_1
\vdots
s_M c_M

Output

Print the answer.

Sample Input 1

3 3
1 7
3 2
1 7

Sample Output 1

702

702 satisfies the conditions - its 1-st and 3-rd digits are 7 and 2, respectively - while no non-negative integer less than 702 satisfies them.

Sample Input 2

3 2
2 1
2 3

Sample Output 2

-1

Sample Input 3

3 1
1 0

Sample Output 3

-1

Submitted source-code file size, in bytes.

Execution CPU time reported by official Project CodeNet metadata, in milliseconds.

Peak memory usage reported by official Project CodeNet metadata, in kilobytes.


;; C - Guess The Number

(defun solve (n sc)
  (loop for i from 0 below (expt 10 n)
        for digits = (map 'array #'digit-char-p (princ-to-string i))
     when (and (= (length digits) n)
               (zerop
                 (loop for (s . c) in sc
                   count (not (eql c (aref digits (1- s)))))))
     do (return i)
     finally (return -1)))

(let* ((n  (read))
       (m  (read))
       (sc (loop repeat m collect (cons (read) (read)))))
  (princ (solve n sc)))


(defun reads (num)
  (loop as i
        below num
        collect (list (read) (read))))

(defun set-num (n l ht)
    (loop as point ; (rank value)
          in l ; (list (rank value))
          do (cond ((< n (car point)) (setf (gethash 'check ht) T)); nより大きい桁に入れようとするとアウト
                   ((and (not (= n 1))
                         (= 1 (car point))
                         (= 0 (cadr point))) (setf (gethash 'check ht) T)); nに0を入れようとしたらアウト
                   ((not (gethash (car point) ht)) (setf (gethash (car point) ht) (cadr point))); まだ入っていないのでOK
                   ((not (= (gethash (car point) ht) (cadr point))) (setf (gethash 'check ht) T))))); 入っていて値が異なるのでアウト

(defun get-number (n ht)
  (loop as i
        below n
        collect (* (expt 10 (- n i 1))
                   (if (gethash (+ i 1) ht)
                       (gethash (+ i 1) ht)
                       (if (= i 0) 1 0)))))

(let ((n (read))
      (c (reads (read)))
      (ht (make-hash-table)))
  (set-num n c ht)
  (if (gethash 'check ht)
      (princ (- 0 1))
      (princ (reduce (lambda (m x) (+ m x)) (get-number n ht)))))


(defun reads (num)
  (loop as i
        below num
        collect (list (read) (read))))

(defun set-num (n l ht)
    (loop as point ; (rank value)
          in l ; (list (rank value))
          do (cond ((< n (car point)) (setf (gethash 'check ht) T)); nより大きい桁に入れようとするとアウト
                   ((and (not (= n 1))
                         (= n (car point))
                         (= 0 (cadr point))) (setf (gethash 'check ht) T)); nに0を入れようとしたらアウト
                   ((not (gethash (car point) ht)) (setf (gethash (car point) ht) (cadr point))); まだ入っていないのでOK
                   ((not (= (gethash (car point) ht) (cadr point))) (setf (gethash 'check ht) T))))); 入っていて値が異なるのでアウト

(defun get-number (n ht)
  (loop as i
        below n
        collect (* (expt 10 (- n i 1))
                   (if (gethash (+ i 1) ht)
                       (gethash (+ i 1) ht)
                       (if (= i 0) 1 0)))))

(let ((n (read))
      (c (reads (read)))
      (ht (make-hash-table)))
  (set-num n c ht)
  (if (gethash 'check ht)
      (princ (- 0 1))
      (princ (reduce (lambda (m x) (+ m x)) (get-number n ht)))))


(defun reads (num)
  (loop as i
        below num
        collect (list (read) (read))))

(defun set-num (n l ht)
    (loop as point ; (rank value)
          in l ; (list (rank value))
          do (cond ((< n (car point)) (setf (gethash 'check ht) T)); nより大きい桁に入れようとするとアウト
                   ((and (= n (car point))
                         (= 0 (cadr point))) (setf (gethash 'check ht) T)); nに0を入れようとしたらアウト
                   ((not (gethash (car point) ht)) (setf (gethash (car point) ht) (cadr point))); まだ入っていないのでOK
                   ((not (= (gethash (car point) ht) (cadr point))) (setf (gethash 'check ht) T))))); 入っていて値が異なるのでアウト

(defun get-number (n ht)
  (loop as i
        below n
        collect (* (expt 10 (- n i 1))
                   (if (gethash (+ i 1) ht)
                       (gethash (+ i 1) ht)
                       (if (= i 0) 1 0)))))

(let ((n (read))
      (c (reads (read)))
      (ht (make-hash-table)))
  (set-num n c ht)
  (if (gethash 'check ht)
      (princ (- 0 1))
      (princ (reduce (lambda (m x) (+ m x)) (get-number n ht)))))


(defun reads (num)
  (loop as i
        below num
        collect (list (read) (read))))

(let* ((n (read))
       (m (read))
       (c (reads m)))
  (princ c))


(let* ((n (read))
       (m (read))
       (lst (loop :repeat m :collect (cons (1- (read)) (read-char)))))
  (if (= n 1)
      (loop :for k :from 0 :upto 9
            :do(print k)
            :if (loop :for (x . y) :in lst
                      :with j = (format nil "~A" k)
                      :always (char= y (aref j x)))
              :do (progn (princ k) (return))
            :finally (princ -1))
      (loop :for k :from (expt 10 (1- n)) :upto (1- (expt 10 n))
            :do(print k)
            :if (loop :for (x . y) :in lst
                      :with j = (format nil "~A" k)
                      :always (char= y (aref j x)))
              :do (progn (princ k) (return))
            :finally (princ -1))))


(let* ((n (read))
       (m (read))
       (lst (loop :repeat m :collect (cons (1- (read)) (read-char)))))
  (loop :for k :from (expt 10 (1- n)) :upto (1- (expt 10 n))
        :if (loop :for (x . y) :in lst
                  :with j = (format nil "~A" k)
                  :always (char= y (aref j x)))
          :do (progn (princ k) (return))
          :finally (princ -1)))


(defun split (str)
  (labels ((inner (rest-str-list stack-str-list temp-out)
                  (if rest-str-list
                      (let ((now-char (car rest-str-list)))
                        (cond ((eq #\space now-char) (inner (cdr rest-str-list)
                                                            '()
                                                            (cons (concatenate 'string (reverse stack-str-list))
                                                                  temp-out)))
                              (t (inner (cdr rest-str-list)
                                        (cons now-char stack-str-list)
                                        temp-out))))
                      (reverse (cons (concatenate 'string (reverse stack-str-list))
                                     temp-out)))))
          (inner (concatenate 'list str)
                 '()
                 '())))

(defun input-to-list (str)
  (mapcar #'parse-integer (split str)))

(defvar nm (input-to-list (read-line)))
(defvar sc (loop for i from 1 to (cadr nm)
                 collect (input-to-list (read-line))))

(defun setnumlst (num-l index num)
  (if (and (zerop num)
           (eq 1 index)
           (not (eq 1 (length num-l))))
      nil
      (if (nth (1- index) num-l)
          (if (eq num (nth (1- index) num-l))
              num-l
              nil)
          (concatenate 'list (subseq num-l 0 (1- index))
                       `(,num)
                       (subseq num-l (1+ (1- index)))))))

(defun fill-first (num-l)
  (if (car num-l)
      num-l
      (concatenate 'list '(,(if (eq 1 (length num-l)) 0 1)) (subseq num-l 1))))

(defun fill-rest (num-l)
  (loop for num in num-l
        collect (if num
                    num
                    0)))

(defun setup (num-l set-l)
  (if set-l
      (let ((next-num-l (setnumlst num-l (caar set-l) (cadar set-l))))
        (if next-num-l
            (setup next-num-l (cdr set-l))
            nil))
      num-l))

(princ (let ((set-num-l (setup (loop for i from 1 to (car nm) collect nil) sc)))
         (if set-num-l
             (parse-integer (apply #'concatenate (cons 'string (loop for num in (fill-rest (fill-first set-num-l))
                                                                     collect (princ-to-string num)))))
             -1)))


(defun split (str)
  (labels ((inner (rest-str-list stack-str-list temp-out)
                  (if rest-str-list
                      (let ((now-char (car rest-str-list)))
                        (cond ((eq #\space now-char) (inner (cdr rest-str-list)
                                                            '()
                                                            (cons (concatenate 'string (reverse stack-str-list))
                                                                  temp-out)))
                              (t (inner (cdr rest-str-list)
                                        (cons now-char stack-str-list)
                                        temp-out))))
                      (reverse (cons (concatenate 'string (reverse stack-str-list))
                                     temp-out)))))
          (inner (concatenate 'list str)
                 '()
                 '())))

(defun input-to-list (str)
  (mapcar #'parse-integer (split str)))

(defvar nm (input-to-list (read-line)))
(defvar sc (loop for i from 1 to (cadr nm)
                 collect (input-to-list (read-line))))

(defun setnumlst (num-l index num)
  (if (and (zerop num)
           (eq 1 index))
      nil
      (if (nth (1- index) num-l)
          (if (eq num (nth (1- index) num-l))
              num-l
              nil)
          (concatenate 'list (subseq num-l 0 (1- index))
                       `(,num)
                       (subseq num-l (1+ (1- index)))))))

(defun fill-first (num-l)
  (if (car num-l)
      num-l
      (concatenate 'list '(1) (subseq num-l 1))))

(defun fill-rest (num-l)
  (loop for num in num-l
        collect (if num
                    num
                    0)))

(defun setup (num-l set-l)
  (if set-l
      (let ((next-num-l (setnumlst num-l (caar set-l) (cadar set-l))))
        (if next-num-l
            (setup next-num-l (cdr set-l))
            nil))
      num-l))

(princ (let ((set-num-l (setup (loop for i from 1 to (car nm) collect nil) sc)))
         (if set-num-l
             (parse-integer (apply #'concatenate (cons 'string (loop for num in (fill-rest (fill-first set-num-l))
                                                                     collect (princ-to-string num)))))
             -1)))


(defun split (str)
  (labels ((inner (rest-str-list stack-str-list temp-out)
                  (if rest-str-list
                      (let ((now-char (car rest-str-list)))
                        (cond ((eq #\space now-char) (inner (cdr rest-str-list)
                                                            '()
                                                            (cons (concatenate 'string (reverse stack-str-list))
                                                                  temp-out)))
                              (t (inner (cdr rest-str-list)
                                        (cons now-char stack-str-list)
                                        temp-out))))
                      (reverse (cons (concatenate 'string (reverse stack-str-list))
                                     temp-out)))))
          (inner (concatenate 'list str)
                 '()
                 '())))

(defun input-to-list (str)
  (mapcar #'parse-integer (split str)))

(defvar nm (input-to-list (read-line)))
(defvar sc (loop for i from 1 to (cadr nm)
                 collect (input-to-list (read-line))))

(defun setnumlst (num-l index num)
  (if (nth (1- index) num-l)
      (if (eq num (nth (1- index) num-l))
          num-l
          nil)
      (concatenate 'list (subseq num-l 0 (1- index))
                   `(,num)
                   (subseq num-l (1+ (1- index))))))

(defun fill-first (num-l)
  (if (car num-l)
      num-l
      (concatenate 'list '(1) (subseq num-l 1))))

(defun fill-rest (num-l)
  (loop for num in num-l
        collect (if num
                    num
                    0)))

(defun setup (num-l set-l)
  (if set-l
      (let ((next-num-l (setnumlst num-l (caar set-l) (cadar set-l))))
        (if next-num-l
            (setup next-num-l (cdr set-l))
            nil))
      num-l))

(defun chk-first-num (num-l)
  (if (zerop (car num-l))
      nil
      num-l))

(princ (let ((set-num-l (chk-first-num (setup (loop for i from 1 to (car nm) collect nil) sc))))
         (if set-num-l
             (parse-integer (apply #'concatenate (cons 'string (loop for num in (fill-rest (fill-first set-num-l))
                                                                    collect (princ-to-string num)))))
             -1)))


(defun split (str)
  (labels ((inner (rest-str-list stack-str-list temp-out)
                  (if rest-str-list
                      (let ((now-char (car rest-str-list)))
                        (cond ((eq #\space now-char) (inner (cdr rest-str-list)
                                                            '()
                                                            (cons (concatenate 'string (reverse stack-str-list))
                                                                  temp-out)))
                              (t (inner (cdr rest-str-list)
                                        (cons now-char stack-str-list)
                                        temp-out))))
                      (reverse (cons (concatenate 'string (reverse stack-str-list))
                                     temp-out)))))
          (inner (concatenate 'list str)
                 '()
                 '())))

(defun input-to-list (str)
  (mapcar #'parse-integer (split str)))

(defvar nm (input-to-list (read-line)))
(defvar sc (loop for i from 1 to (cadr nm)
                 collect (input-to-list (read-line))))

(defun setnumlst (num-l index num)
  (if (nth (1- index) num-l)
      (if (eq num (nth (1- index) num-l))
          num-l
          nil)
      (concatenate 'list (subseq num-l 0 (1- index))
                   `(,num)
                   (subseq num-l (1+ (1- index))))))

(defun fill-first (num-l)
  (if (car num-l)
      num-l
      (concatenate 'list '(1) (subseq num-l 1))))

(defun fill-rest (num-l)
  (loop for num in num-l
        collect (if num
                    num
                    0)))

(defun setup (num-l set-l)
  (if set-l
      (let ((next-num-l (setnumlst num-l (caar set-l) (cadar set-l))))
        (if next-num-l
            (setup next-num-l (cdr set-l))
            nil))
      num-l))

(princ (let ((set-num-l (setup (loop for i from 1 to (car nm) collect nil) sc)))
         (if set-num-l
             (parse-integer (apply #'concatenate (cons 'string (loop for num in (fill-rest (fill-first set-num-l))
                                                                    collect (princ-to-string num)))))
             -1)))


(defun get-input-array2 (n m)
  (let ((rst (make-array (list n m))))
    (loop for x from 0 to (- n 1)
          do (loop for y from 0 to (- m 1)
                   ;do (format t "~A ~A ~%" x y)
                   do (setf (aref rst x y) (read))))
    rst))

(defun main (n m)
  (let* ((input-array (get-input-array2 m 2))
         (rst-array (make-array n :initial-element 0))
         (rst 0))
    (loop for x from 0 to (- m 1)
          for si =  (- (aref input-array x 0) 1)
          for ci = (aref input-array x 1)
          if (or (and (not (equal (aref rst-array si) 0)) (not (equal ci (aref rst-array si))))
                 (and (equal si 0) (equal ci 0) (not (equal n 1))))
          do (progn (setf rst -1)
               (return))
          do (setf (aref rst-array si) ci)
          ;do (format t "1: ~A ~A ~A~%" x si ci)
          finally (if (and (not (equal n 1)) (equal (aref rst-array 0) 0))
                      (setf (aref rst-array 0) 1)))
    (loop for x downfrom (- n 1) downto 0
          for y from 0 to n
          for z = (aref rst-array y)
          if (equal rst -1)
          do (return)
          ;do (format t "2: ~A ~A ~A ~%" x y z)
          do (setf rst (+ rst (* z (expt 10 x)))))
    rst))

(format t "~A~%" (main (read) (read)))


(defun splitat (c line)
  (labels ((rec (line acc)
				(let ((pos (position-if (lambda(cc) (char= c cc)) line)))
				  (if pos
					  (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))
					(nreverse (cons line acc))))))
	(rec line nil)))
(defun f(n m lst notfoundcallback foundcallback)
  (let ((num (loop for i from 1 to n collect 0)))
    (labels ((rec (num lst)
                  (if (null lst)
                    (funcall foundcallback (reduce #'+ (mapcar #'* num (loop for i from 1 to n collect (expt 10 (- n i))))))
                    (if (or (zerop (nth (1- (car (car lst))) num))
                            (= (nth (1- (car (car lst))) num) (cadr (car lst))))
                      (progn
                        (setf (nth (1- (car (car lst))) num) (cadr (car lst)))
                        (rec num (cdr lst)))
                      (funcall notfoundcallback))
                      )))
      (rec num lst))))
(let* ((nm (mapcar #'parse-integer (splitat #\space (read-line nil nil))))
       (lst nil))
  (dotimes (i (cadr nm))
    (setq lst (cons (mapcar #'parse-integer (splitat #\space (read-line nil nil))) lst)))
  (f (car nm) (cadr nm) lst (lambda() (format t "-1~%")) (lambda(n) (format t "~A~%" n))))


(let* ((n (read))
       (m (read))
       (cs (loop repeat m
                 collect (cons (read) (read))))
       (dig (make-array n :initial-element -1))
       (valid t)
       (result))
  (loop for (s . c) in cs
        do (progn
             (when (and (<= 0 (aref dig (- s 1)))
                        (/= c (aref dig (- s 1))))
               (setf valid nil)
               (loop-finish))
             (setf (aref dig (- s 1)) c)))
  (loop for i from 0 below n
        with ldig = nil
        for d = (aref dig i)
        do (push (if (<= 0 d)
                     (progn
                       (setf ldig t)
                       d)
                     (if (or (not (zerop i)) ldig)
                         0 1))
                 result))
  (setf result (nreverse result))
  (when (and (zerop (car result))
             (cdr result))
    (setf valid nil))
  (if valid
      (format t "~{~a~}~%" result)
      (format t "-1~%")))


(defun num-to-char (num)
  (code-char (+ num (char-code #\0))))

(defun solve (n m pairs)
  (let ((num (make-array n :element-type 'character :initial-element #\-)))
    (loop for (s . c) in pairs
          if (char= #\- (aref num (1- s)))
          do (setf (aref num (1- s)) (num-to-char c))
          else if (char/= (aref num (1- s)) (num-to-char c))
          do (return-from solve -1))
    (when (char= (aref num 0) #\-)
      (setf (aref num 0) #\1))
    (loop for i from 0
          for n across num
          if (char= n #\-)
          do (setf (aref num i) #\0))
    (if (and (< 1 n)
             (char= (aref num 0) #\0))
        -1
        (read-from-string num))))

#-swank
(let* ((n (read))
       (m (read))
       (pairs (loop repeat m collect (cons (read) (read)))))
  (format t "~A~%" (solve n m pairs)))


(defun num-to-char (num)
  (code-char (+ num (char-code #\0))))

(defun solve (n m pairs)
  (let ((num (make-array n :element-type 'character :initial-element #\-)))
    (loop for (s . c) in pairs
          if (char= #\- (aref num (1- s)))
          do (setf (aref num (1- s)) (num-to-char c))
          else if (char/= (aref num (1- s)) (num-to-char c))
          do (return-from solve -1))
    (loop for i from 0
          for n across num
          if (char= n #\-)
          do (setf (aref num i) #\0))
    (when (char= (aref num 0) #\-)
      (setf (aref num 0) #\1))
    (if (char= (aref num 0) #\0)
        -1
        (read-from-string num))))

#-swank
(let* ((n (read))
       (m (read))
       (pairs (loop repeat m collect (cons (read) (read)))))
  (format t "~A~%" (solve n m pairs)))


(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
           ;; enclose the form with VALUES to avoid being captured by LOOP macro
           #\# #\> (lambda (s c p) (declare (ignore c p)) `(values ,(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
(declaim (ftype (function * (values fixnum &optional)) read-fixnum))
(defun read-fixnum (&optional (in *standard-input*))
  "NOTE: cannot read -2^62"
  (declare #.OPT)
  (macrolet ((%read-byte ()
               `(the (unsigned-byte 8)
                     #+swank (char-code (read-char in nil #\Nul))
                     #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\Nul) nil))))
    (let* ((minus nil)
           (result (loop (let ((byte (%read-byte)))
                           (cond ((<= 48 byte 57)
                                  (return (- byte 48)))
                                 ((zerop byte) ; #\Nul
                                  (error "Read EOF or #\Nul."))
                                 ((= byte #.(char-code #\-))
                                  (setf minus t)))))))
      (declare ((integer 0 #.most-positive-fixnum) result))
      (loop
        (let* ((byte (%read-byte)))
          (if (<= 48 byte 57)
              (setq result (+ (- byte 48)
                              (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))
                                         result))))
              (return (if minus (- result) result))))))))

(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 sort< (as)
  (declare #.OPT
           (inline sort)
           ((simple-array int32 (*)) as))
  (sort as #'<))

(defun sort> (as)
  (declare #.OPT
           (inline sort)
           ((simple-array int32 (*)) as))
  (sort as #'>))

(defun main ()
  (declare #.OPT)
  (let* ((n (read))
         (k (read))
         (as (make-array n :element-type 'int32))
         (as+ (make-array n :fill-pointer 0 :element-type 'int32))
         (as- (make-array n :fill-pointer 0 :element-type 'int32)))
    (declare (uint31 n k))
    (dotimes (i n)
      (let ((a (read-fixnum)))
        (setf (aref as i) a)
        (vector-push a (if (>= a 0) as+ as-))))
    (let* ((as+< (sort< (coerce as+ '(simple-array int32 (*)))))
           (as+> (sort> (coerce as+ '(simple-array int32 (*)))))
           (as-< (sort< (coerce as- '(simple-array int32 (*)))))
           (as-> (sort> (coerce as- '(simple-array int32 (*))))))
      (declare ((simple-array int32 (*)) as+< as+> as-< as->))
      (labels ((calc-count (threshold)
                 (declare (fixnum threshold))
                 (let ((res 0))
                   (declare (uint62 res))
                   (when (>= threshold 0)
                     (let ((end 0))
                       (sb-int:dovector (a as+>)
                         (loop until (or (= end (length as+<))
                                         (< threshold (* a (aref as+< end))))
                               do (incf end)
                               finally (incf res end)))))
                   (if (>= threshold 0)
                       (incf res (the uint62 (* (length as+<) (length as-<))))
                       (let ((end 0))
                         (sb-int:dovector (a as+<)
                           (loop until (or (= end (length as-<))
                                           (< threshold (* a (aref as-< end))))
                                 do (incf end)
                                 finally (incf res end)))))
                   (if (>= threshold 0)
                       (incf res (the uint62 (* (length as+<) (length as-<))))
                       (let ((end 0))
                         (sb-int:dovector (a as->)
                           (loop until (or (= end (length as+>))
                                           (< threshold (* a (aref as+> end))))
                                 do (incf end)
                                 finally (incf res end)))))
                   (when (>= threshold 0)
                     (let ((end 0))
                       (sb-int:dovector (a as-<)
                         (loop until (or (= end (length as->))
                                         (< threshold (* a (aref as-> end))))
                               do (incf end)
                               finally (incf res end)))))
                   (sb-int:dovector (a as)
                     (when (<= (* a a) threshold)
                       (decf res)))
                   (setq res (ash res -1))
                   res)))
        (sb-int:named-let bisect ((ng #.(- (expt 10 18))) (ok #.(+ 1 (expt 10 18))))
          (declare (fixnum ng ok))
          (if (<= (- ok ng) 1)
              (println ok)
              (let ((mid (floor (+ ng ok) 2)))
                (if (>= (calc-count mid) k)
                    (bisect ng mid)
                    (bisect mid ok)))))))))

#-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 "powershell.exe" '("-Command" "Get-Clipboard") :output out :search t)))

#+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 3
3 3 -4 -2
"
    "-6
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "10 40
5 4 3 2 -1 0 0 0 0 0
"
    "6
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "30 413
-170202098 -268409015 537203564 983211703 21608710 -443999067 -937727165 -97596546 -372334013 398994917 -972141167 798607104 -949068442 -959948616 37909651 0 886627544 -20098238 0 -948955241 0 -214720580 277222296 -18897162 834475626 0 -425610555 110117526 663621752 0
"
    "448283280358331064
")))

Score: 400 points

Problem Statement

We have N integers A_1, A_2, ..., A_N.

There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list?

Constraints

All values in input are integers.

2 \leq N \leq 2 \times 10^5

1 \leq K \leq \frac{N(N-1)}{2}

-10^9 \leq A_i \leq 10^9\ (1 \leq i \leq N)

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \dots A_N

Output

Print the answer.

Sample Input 1

4 3
3 3 -4 -2

Sample Output 1

-6

There are six ways to form a pair. The products of those pairs are 9, -12, -6, -12, -6, 8.

Sorting those numbers in ascending order, we have -12, -12, -6, -6, 8, 9. The third number in this list is -6.

Sample Input 2

10 40
5 4 3 2 -1 0 0 0 0 0

Sample Output 2

6

Sample Input 3

30 413
-170202098 -268409015 537203564 983211703 21608710 -443999067 -937727165 -97596546 -372334013 398994917 -972141167 798607104 -949068442 -959948616 37909651 0 886627544 -20098238 0 -948955241 0 -214720580 277222296 -18897162 834475626 0 -425610555 110117526 663621752 0

Sample Output 3

448283280358331064


(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
           ;; enclose the form with VALUES to avoid being captured by LOOP macro
           #\# #\> (lambda (s c p) (declare (ignore c p)) `(values ,(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
(declaim (ftype (function * (values fixnum &optional)) read-fixnum))
(defun read-fixnum (&optional (in *standard-input*))
  "NOTE: cannot read -2^62"
  (declare #.OPT)
  (macrolet ((%read-byte ()
               `(the (unsigned-byte 8)
                     #+swank (char-code (read-char in nil #\Nul))
                     #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\Nul) nil))))
    (let* ((minus nil)
           (result (loop (let ((byte (%read-byte)))
                           (cond ((<= 48 byte 57)
                                  (return (- byte 48)))
                                 ((zerop byte) ; #\Nul
                                  (error "Read EOF or #\Nul."))
                                 ((= byte #.(char-code #\-))
                                  (setf minus t)))))))
      (declare ((integer 0 #.most-positive-fixnum) result))
      (loop
        (let* ((byte (%read-byte)))
          (if (<= 48 byte 57)
              (setq result (+ (- byte 48)
                              (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))
                                         result))))
              (return (if minus (- result) result))))))))

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

(declaim (ftype (function * (values uint31 &optional)) bisect-right))
(defun bisect-right (target value pivot)
  (declare #.OPT
           (int32 pivot)
           (fixnum value)
           ((simple-array int32 (*)) target))
  (sb-int:named-let bisect ((left 0) (ok (length target)))
    (declare ((integer 0 #.most-positive-fixnum) left ok))
    (let ((mid (ash (+ left ok) -1)))
      (if (= mid left)
          (if (< value (the fixnum (* pivot (aref target left))))
              left
              ok)
          (if (< value (the fixnum (* pivot (aref target mid))))
              (bisect left mid)
              (bisect mid ok))))))

(defun sort< (as)
  (declare #.OPT
           (inline sort)
           ((simple-array int32 (*)) as))
  (sort as #'<))

(defun sort> (as)
  (declare #.OPT
           (inline sort)
           ((simple-array int32 (*)) as))
  (sort as #'>))

(defun main ()
  (declare #.OPT)
  (let* ((n (read))
         (k (read))
         (as (make-array n :element-type 'int32)))
    (declare (uint31 n k))
    (dotimes (i n)
      (setf (aref as i) (read-fixnum)))
    (let ((as< (sort< (copy-seq as)))
          (as> (sort> (copy-seq as))))
      (declare ((simple-array int32 (*)) as< as>))
      (labels ((calc-count (threshold)
                 (declare (fixnum threshold))
                 (let ((res 0))
                   (declare (uint62 res))
                   (sb-int:dovector (a as)
                     (incf res (bisect-right (if (>= a 0) as< as>)
                                             threshold
                                             a)))
                   (sb-int:dovector (a as)
                     (when (<= (* a a) threshold)
                       (decf res)))
                   (setq res (ash res -1))
                   res)))
        (sb-int:named-let bisect ((ng #.(- (expt 10 18))) (ok #.(+ 1 (expt 10 18))))
          (declare (fixnum ng ok))
          (if (<= (- ok ng) 1)
              (println ok)
              (let ((mid (floor (+ ng ok) 2)))
                (if (>= (calc-count mid) k)
                    (bisect ng mid)
                    (bisect mid ok)))))))))

#-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 "powershell.exe" '("-Command" "Get-Clipboard") :output out :search t)))

#+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 3
3 3 -4 -2
"
    "-6
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "10 40
5 4 3 2 -1 0 0 0 0 0
"
    "6
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "30 413
-170202098 -268409015 537203564 983211703 21608710 -443999067 -937727165 -97596546 -372334013 398994917 -972141167 798607104 -949068442 -959948616 37909651 0 886627544 -20098238 0 -948955241 0 -214720580 277222296 -18897162 834475626 0 -425610555 110117526 663621752 0
"
    "448283280358331064
")))


(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
           ;; enclose the form with VALUES to avoid being captured by LOOP macro
           #\# #\> (lambda (s c p) (declare (ignore c p)) `(values ,(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
(declaim (ftype (function * (values fixnum &optional)) read-fixnum))
(defun read-fixnum (&optional (in *standard-input*))
  "NOTE: cannot read -2^62"
  (declare #.OPT)
  (macrolet ((%read-byte ()
               `(the (unsigned-byte 8)
                     #+swank (char-code (read-char in nil #\Nul))
                     #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\Nul) nil))))
    (let* ((minus nil)
           (result (loop (let ((byte (%read-byte)))
                           (cond ((<= 48 byte 57)
                                  (return (- byte 48)))
                                 ((zerop byte) ; #\Nul
                                  (error "Read EOF or #\Nul."))
                                 ((= byte #.(char-code #\-))
                                  (setf minus t)))))))
      (declare ((integer 0 #.most-positive-fixnum) result))
      (loop
        (let* ((byte (%read-byte)))
          (if (<= 48 byte 57)
              (setq result (+ (- byte 48)
                              (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))
                                         result))))
              (return (if minus (- result) result))))))))

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

(declaim (ftype (function * (values uint31 &optional)) bisect-right))
(defun bisect-right (target value pivot)
  (declare #.OPT
           (int32 pivot)
           (fixnum value)
           ((simple-array int32 (*)) target))
  (sb-int:named-let bisect ((left 0) (ok (length target)))
    (declare ((integer 0 #.most-positive-fixnum) left ok))
    (let ((mid (ash (+ left ok) -1)))
      (if (= mid left)
          (if (< value (the fixnum (* pivot (aref target left))))
              left
              ok)
          (if (< value (the fixnum (* pivot (aref target mid))))
              (bisect left mid)
              (bisect mid ok))))))

(defun sort< (as)
  (declare #.OPT
           (inline sort)
           ((simple-array int32 (*)) as))
  (sort as #'<))

(defun sort> (as)
  (declare #.OPT
           (inline sort)
           ((simple-array int32 (*)) as))
  (sort as #'>))

(defun main ()
  (declare #.OPT)
  (let* ((n (read))
         (k (read))
         (as (make-array n :element-type 'int32))
         (as+ (make-array n :fill-pointer 0 :element-type 'int32))
         (as- (make-array n :fill-pointer 0 :element-type 'int32)))
    (declare (uint31 n k))
    (dotimes (i n)
      (let ((a (read-fixnum)))
        (setf (aref as i) a)
        (vector-push a (if (>= a 0) as+ as-))))
    (let ((as+< (sort< (coerce as+ '(simple-array int32 (*)))))
          (as+> (sort> (coerce as+ '(simple-array int32 (*)))))
          (as-< (sort< (coerce as- '(simple-array int32 (*)))))
          (as-> (sort> (coerce as- '(simple-array int32 (*))))))
      (declare ((simple-array int32 (*)) as+< as+> as-< as->))
      #>as+<
      #>as+>
      (labels ((calc-count (threshold)
                 (declare (fixnum threshold))
                 (let ((res 0))
                   (declare (uint62 res))
                   (let ((end 0))
                     (sb-int:dovector (a as+>)
                       (loop until (or (= end (length as+<))
                                       (< threshold (* a (aref as+< end))))
                             do (incf end)
                             finally (dbg a end)
                                     (incf res end))))
                   (let ((end 0))
                     (sb-int:dovector (a as+>)
                       (loop until (or (= end (length as->))
                                       (< threshold (* a (aref as-> end))))
                             do (incf end)
                             finally (dbg a end)
                                     (incf res end))))
                   (let ((end 0))
                     (sb-int:dovector (a as->)
                       (loop until (or (= end (length as+>))
                                       (< threshold (* a (aref as+> end))))
                             do (incf end)
                             finally (dbg a end)
                                     (incf res end))))
                   (let ((end 0))
                     (sb-int:dovector (a as-<)
                       (loop until (or (= end (length as->))
                                       (< threshold (* a (aref as-> end))))
                             do (incf end)
                             finally (dbg a end)
                                     (incf res end))))
                   (sb-int:dovector (a as)
                     (when (<= (* a a) threshold)
                       (decf res)))
                   (setq res (ash res -1))
                   res)))
        (sb-int:named-let bisect ((ng #.(- (expt 10 18))) (ok #.(+ 1 (expt 10 18))))
          (declare (fixnum ng ok))
          (if (<= (- ok ng) 1)
              (println ok)
              (let ((mid (floor (+ ng ok) 2)))
                (if (>= (calc-count mid) k)
                    (bisect ng mid)
                    (bisect mid ok)))))))))

#-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 "powershell.exe" '("-Command" "Get-Clipboard") :output out :search t)))

#+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 3
3 3 -4 -2
"
    "-6
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "10 40
5 4 3 2 -1 0 0 0 0 0
"
    "6
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "30 413
-170202098 -268409015 537203564 983211703 21608710 -443999067 -937727165 -97596546 -372334013 398994917 -972141167 798607104 -949068442 -959948616 37909651 0 886627544 -20098238 0 -948955241 0 -214720580 277222296 -18897162 834475626 0 -425610555 110117526 663621752 0
"
    "448283280358331064
")))


(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
           ;; enclose the form with VALUES to avoid being captured by LOOP macro
           #\# #\> (lambda (s c p) (declare (ignore c p)) `(values ,(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
(declaim (ftype (function * (values fixnum &optional)) read-fixnum))
(defun read-fixnum (&optional (in *standard-input*))
  "NOTE: cannot read -2^62"
  (declare #.OPT)
  (macrolet ((%read-byte ()
               `(the (unsigned-byte 8)
                     #+swank (char-code (read-char in nil #\Nul))
                     #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\Nul) nil))))
    (let* ((minus nil)
           (result (loop (let ((byte (%read-byte)))
                           (cond ((<= 48 byte 57)
                                  (return (- byte 48)))
                                 ((zerop byte) ; #\Nul
                                  (error "Read EOF or #\Nul."))
                                 ((= byte #.(char-code #\-))
                                  (setf minus t)))))))
      (declare ((integer 0 #.most-positive-fixnum) result))
      (loop
        (let* ((byte (%read-byte)))
          (if (<= 48 byte 57)
              (setq result (+ (- byte 48)
                              (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))
                                         result))))
              (return (if minus (- result) result))))))))

(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 bisect-right (target value pivot)
  (declare #.OPT
           (int32 pivot)
           (fixnum value)
           ((simple-array int32 (*)) target))
  (sb-int:named-let bisect ((left 0) (ok (length target)))
    (declare ((integer 0 #.most-positive-fixnum) left ok))
    (let ((mid (ash (+ left ok) -1)))
      (if (= mid left)
          (if (< value (the fixnum (* pivot (aref target left))))
              left
              ok)
          (if (< value (the fixnum (* pivot (aref target mid))))
              (bisect left mid)
              (bisect mid ok))))))

(defun sort< (as)
  (declare #.OPT
           (inline sort)
           ((simple-array int32 (*)) as))
  (sort as #'<))

(defun sort> (as)
  (declare #.OPT
           (inline sort)
           ((simple-array int32 (*)) as))
  (sort as #'>))

(defun main ()
  (declare #.OPT)
  (let* ((n (read))
         (k (read))
         (as (make-array n :element-type 'int32))
         (as+ (make-array n :fill-pointer 0 :element-type 'int32))
         (as- (make-array n :fill-pointer 0 :element-type 'int32)))
    (declare (uint31 n k))
    (dotimes (i n)
      (let ((a (read-fixnum)))
        (setf (aref as i) a)
        (cond ((>= a 0)
               (vector-push a as+))
              ((< a 0)
               (vector-push a as-)))))
    (let ((as+< (sort< (coerce as+ '(simple-array int32 (*)))))
          (as-< (sort< (coerce as- '(simple-array int32 (*)))))
          (as+> (sort> (coerce as+ '(simple-array int32 (*)))))
          (as-> (sort> (coerce as- '(simple-array int32 (*))))))
      (declare ((simple-array int32 (*)) as+< as-< as+> as->))
      (labels ((calc (pivot threshold)
                 (declare (int32 pivot)
                          (fixnum threshold))
                 (let ((res 0))
                   (declare (uint62 res))
                   (cond ((= pivot 0)
                          (incf res (if (>= threshold 0) n 0)))
                         ((and (> pivot 0) (>= threshold 0))
                          (incf res (the uint31 (bisect-right as+< threshold pivot)))
                          (incf res (length as->)))
                         ((and (> pivot 0) (< threshold 0))
                          (incf res (the uint31 (bisect-right as-< threshold pivot))))
                         ((and (< pivot 0) (>= threshold 0))
                          (incf res (the uint31 (bisect-right as-> threshold pivot)))
                          (incf res (length as+>)))
                         ((and (< pivot 0) (< threshold 0))
                          (incf res (the uint31 (bisect-right as+> threshold pivot)))))
                   ;; (dbg pivot threshold res)
                   res))
               (calc-count (threshold)
                 (declare (fixnum threshold))
                 (let ((res 0))
                   (declare (uint62 res))
                   (sb-int:dovector (a as)
                     (incf res (calc a threshold)))
                   (sb-int:dovector (a as)
                     (when (<= (* a a) threshold)
                       (decf res)))
                   (setq res (ash res -1))
                   ;; (dbg res threshold)
                   res)))
        ;; #>(calc-count 0)
        (sb-int:named-let bisect ((ng #.(- (expt 10 18))) (ok #.(+ 1 (expt 10 18))))
          (declare (fixnum ng ok))
          (if (<= (- ok ng) 1)
              (println ok)
              (let ((mid (floor (+ ng ok) 2)))
                (if (>= (calc-count mid) k)
                    (bisect ng mid)
                    (bisect mid ok)))))
        ))))

#-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 "powershell.exe" '("-Command" "Get-Clipboard") :output out :search t)))

#+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 3
3 3 -4 -2
"
    "-6
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "10 40
5 4 3 2 -1 0 0 0 0 0
"
    "6
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "30 413
-170202098 -268409015 537203564 983211703 21608710 -443999067 -937727165 -97596546 -372334013 398994917 -972141167 798607104 -949068442 -959948616 37909651 0 886627544 -20098238 0 -948955241 0 -214720580 277222296 -18897162 834475626 0 -425610555 110117526 663621752 0
"
    "448283280358331064
")))


(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
           ;; enclose the form with VALUES to avoid being captured by LOOP macro
           #\# #\> (lambda (s c p) (declare (ignore c p)) `(values ,(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
(declaim (ftype (function * (values fixnum &optional)) read-fixnum))
(defun read-fixnum (&optional (in *standard-input*))
  "NOTE: cannot read -2^62"
  (declare #.OPT)
  (macrolet ((%read-byte ()
               `(the (unsigned-byte 8)
                     #+swank (char-code (read-char in nil #\Nul))
                     #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\Nul) nil))))
    (let* ((minus nil)
           (result (loop (let ((byte (%read-byte)))
                           (cond ((<= 48 byte 57)
                                  (return (- byte 48)))
                                 ((zerop byte) ; #\Nul
                                  (error "Read EOF or #\Nul."))
                                 ((= byte #.(char-code #\-))
                                  (setf minus t)))))))
      (declare ((integer 0 #.most-positive-fixnum) result))
      (loop
        (let* ((byte (%read-byte)))
          (if (<= 48 byte 57)
              (setq result (+ (- byte 48)
                              (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))
                                         result))))
              (return (if minus (- result) result))))))))

(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 bisect-right (target value pivot)
  (declare #.OPT
           (int32 pivot)
           (fixnum value)
           ((simple-array int32 (*)) target))
  (sb-int:named-let bisect ((left 0) (ok (length target)))
    (declare ((integer 0 #.most-positive-fixnum) left ok))
    (let ((mid (ash (+ left ok) -1)))
      (if (= mid left)
          (if (< value (the fixnum (* pivot (aref target left))))
              left
              ok)
          (if (< value (the fixnum (* pivot (aref target mid))))
              (bisect left mid)
              (bisect mid ok))))))

(defun sort< (as)
  (declare #.OPT
           (inline sort)
           ((simple-array int32 (*)) as))
  (sort as #'<))

(defun sort> (as)
  (declare #.OPT
           (inline sort)
           ((simple-array int32 (*)) as))
  (sort as #'>))

(defun main ()
  (declare #.OPT)
  (let* ((n (read))
         (k (read))
         (as (make-array n :element-type 'int32))
         (as+ (make-array n :fill-pointer 0 :element-type 'int32))
         (as- (make-array n :fill-pointer 0 :element-type 'int32)))
    (declare (uint31 n k))
    (dotimes (i n)
      (let ((a (read-fixnum)))
        (setf (aref as i) a)
        (cond ((>= a 0)
               (vector-push a as+))
              ((< a 0)
               (vector-push a as-)))))
    (let ((as+< (sort< (coerce as+ '(simple-array int32 (*)))))
          (as-< (sort< (coerce as- '(simple-array int32 (*)))))
          (as+> (sort> (coerce as+ '(simple-array int32 (*)))))
          (as-> (sort> (coerce as- '(simple-array int32 (*))))))
      (declare ((simple-array int32 (*)) as+< as-< as+> as->))
      (labels ((calc (pivot threshold)
                 (declare (int32 pivot)
                          (fixnum threshold))
                 (let ((res 0))
                   (declare (uint62 res))
                   (cond ((= pivot 0)
                          (incf res (if (> threshold 0) n 0)))
                         ((and (> pivot 0) (>= threshold 0))
                          (incf res (the uint31 (bisect-right as+< threshold pivot)))
                          (incf res (length as->)))
                         ((and (> pivot 0) (< threshold 0))
                          (incf res (the uint31 (bisect-right as-< threshold pivot))))
                         ((and (< pivot 0) (>= threshold 0))
                          (incf res (the uint31 (bisect-right as-> threshold pivot)))
                          (incf res (length as+>)))
                         ((and (< pivot 0) (< threshold 0))
                          (incf res (the uint31 (bisect-right as+> threshold pivot)))))
                   res))
               (calc-count (threshold)
                 (declare (fixnum threshold))
                 (let ((res 0))
                   (declare (uint62 res))
                   (sb-int:dovector (a as)
                     (incf res (calc a threshold)))
                   (sb-int:dovector (a as)
                     (when (< (* a a) threshold)
                       (decf res)))
                   (setq res (ash res -1))
                   res)))
        (sb-int:named-let bisect ((ng #.(- (expt 10 18))) (ok #.(+ 1 (expt 10 18))))
          (declare (fixnum ng ok))
          (if (<= (- ok ng) 1)
              (println ok)
              (let ((mid (floor (+ ng ok) 2)))
                (if (>= (calc-count mid) k)
                    (bisect ng mid)
                    (bisect mid ok)))))))))

#-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 "powershell.exe" '("-Command" "Get-Clipboard") :output out :search t)))

#+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 3
3 3 -4 -2
"
    "-6
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "10 40
5 4 3 2 -1 0 0 0 0 0
"
    "6
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "30 413
-170202098 -268409015 537203564 983211703 21608710 -443999067 -937727165 -97596546 -372334013 398994917 -972141167 798607104 -949068442 -959948616 37909651 0 886627544 -20098238 0 -948955241 0 -214720580 277222296 -18897162 834475626 0 -425610555 110117526 663621752 0
"
    "448283280358331064
")))


(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
           ;; enclose the form with VALUES to avoid being captured by LOOP macro
           #\# #\> (lambda (s c p) (declare (ignore c p)) `(values ,(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
(declaim (ftype (function * (values fixnum &optional)) read-fixnum))
(defun read-fixnum (&optional (in *standard-input*))
  "NOTE: cannot read -2^62"
  (declare #.OPT)
  (macrolet ((%read-byte ()
               `(the (unsigned-byte 8)
                     #+swank (char-code (read-char in nil #\Nul))
                     #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\Nul) nil))))
    (let* ((minus nil)
           (result (loop (let ((byte (%read-byte)))
                           (cond ((<= 48 byte 57)
                                  (return (- byte 48)))
                                 ((zerop byte) ; #\Nul
                                  (error "Read EOF or #\Nul."))
                                 ((= byte #.(char-code #\-))
                                  (setf minus t)))))))
      (declare ((integer 0 #.most-positive-fixnum) result))
      (loop
        (let* ((byte (%read-byte)))
          (if (<= 48 byte 57)
              (setq result (+ (- byte 48)
                              (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))
                                         result))))
              (return (if minus (- result) result))))))))

(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 bisect-right (target value pivot)
  (declare #.OPT
           (int31 pivot)
           (fixnum value)
           ((simple-array int31 (*)) target))
  (sb-int:named-let bisect ((left 0) (ok (length target)))
    (declare ((integer 0 #.most-positive-fixnum) left ok))
    (let ((mid (ash (+ left ok) -1)))
      (if (= mid left)
          (if (< value (the fixnum (* pivot (aref target left))))
              left
              ok)
          (if (< value (the fixnum (* pivot (aref target mid))))
              (bisect left mid)
              (bisect mid ok))))))

(defun sort< (as)
  (declare #.OPT
           (inline sort)
           ((simple-array int31 (*)) as))
  (sort as #'<))

(defun sort> (as)
  (declare #.OPT
           (inline sort)
           ((simple-array int31 (*)) as))
  (sort as #'>))

(defun main ()
  (declare #.OPT)
  (let* ((n (read))
         (k (read))
         (as (make-array n :element-type 'int31))
         (as+ (make-array n :fill-pointer 0 :element-type 'int31))
         (as- (make-array n :fill-pointer 0 :element-type 'int31)))
    (declare (uint31 n k))
    (dotimes (i n)
      (let ((a (read-fixnum)))
        (setf (aref as i) a)
        (if (>= a 0)
            (vector-push a as+)
            (vector-push a as-))))
    (let ((as+< (sort< (coerce as+ '(simple-array int31 (*)))))
          (as-< (sort< (coerce as- '(simple-array int31 (*)))))
          (as+> (sort> (coerce as+ '(simple-array int31 (*)))))
          (as-> (sort> (coerce as- '(simple-array int31 (*))))))
      (declare ((simple-array int31 (*)) as+< as-< as+> as->))
      (labels ((calc (pivot threshold)
                 (declare (int31 pivot)
                          (fixnum threshold))
                 (let ((res 0))
                   (declare (uint62 res))
                   (cond ((and (>= pivot 0) (>= threshold 0))
                          (incf res (the uint31 (bisect-right as+< threshold pivot)))
                          (incf res (length as->)))
                         ((and (>= pivot 0) (< threshold 0))
                          (incf res (the uint31 (bisect-right as-< threshold pivot))))
                         ((and (< pivot 0) (>= threshold 0))
                          (incf res (the uint31 (bisect-right as-> threshold pivot)))
                          (incf res (length as+>)))
                         ((and (< pivot 0) (< threshold 0))
                          (incf res (the uint31 (bisect-right as+> threshold pivot)))))
                   res))
               (calc-count (threshold)
                 (declare (fixnum threshold))
                 (let ((res 0))
                   (declare (uint62 res))
                   (sb-int:dovector (a as)
                     (incf res (calc a threshold)))
                   (sb-int:dovector (a as)
                     (when (< (* a a) threshold)
                       (decf res)))
                   (setq res (ash res -1))
                   res)))
        (sb-int:named-let bisect ((ng most-negative-fixnum) (ok most-positive-fixnum))
          (declare (fixnum ng ok))
          (if (<= (- ok ng) 1)
              (println ok)
              (let ((mid (floor (+ ng ok) 2)))
                (if (>= (calc-count mid) k)
                    (bisect ng mid)
                    (bisect mid ok)))))))))

#-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 "powershell.exe" '("-Command" "Get-Clipboard") :output out :search t)))

#+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 3
3 3 -4 -2
"
    "-6
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "10 40
5 4 3 2 -1 0 0 0 0 0
"
    "6
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "30 413
-170202098 -268409015 537203564 983211703 21608710 -443999067 -937727165 -97596546 -372334013 398994917 -972141167 798607104 -949068442 -959948616 37909651 0 886627544 -20098238 0 -948955241 0 -214720580 277222296 -18897162 834475626 0 -425610555 110117526 663621752 0
"
    "448283280358331064
")))


(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
           ;; enclose the form with VALUES to avoid being captured by LOOP macro
           #\# #\> (lambda (s c p) (declare (ignore c p)) `(values ,(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
(declaim (ftype (function * (values fixnum &optional)) read-fixnum))
(defun read-fixnum (&optional (in *standard-input*))
  "NOTE: cannot read -2^62"
  (declare #.OPT)
  (macrolet ((%read-byte ()
               `(the (unsigned-byte 8)
                     #+swank (char-code (read-char in nil #\Nul))
                     #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\Nul) nil))))
    (let* ((minus nil)
           (result (loop (let ((byte (%read-byte)))
                           (cond ((<= 48 byte 57)
                                  (return (- byte 48)))
                                 ((zerop byte) ; #\Nul
                                  (error "Read EOF or #\Nul."))
                                 ((= byte #.(char-code #\-))
                                  (setf minus t)))))))
      (declare ((integer 0 #.most-positive-fixnum) result))
      (loop
        (let* ((byte (%read-byte)))
          (if (<= 48 byte 57)
              (setq result (+ (- byte 48)
                              (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))
                                         result))))
              (return (if minus (- result) result))))))))

(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 bisect-right (target value pivot)
  (declare #.OPT
           (int32 pivot)
           (fixnum value)
           ((simple-array int32 (*)) target))
  (sb-int:named-let bisect ((left 0) (ok (length target)))
    (declare ((integer 0 #.most-positive-fixnum) left ok))
    (let ((mid (ash (+ left ok) -1)))
      (if (= mid left)
          (if (< value (the fixnum (* pivot (aref target left))))
              left
              ok)
          (if (< value (the fixnum (* pivot (aref target mid))))
              (bisect left mid)
              (bisect mid ok))))))

(defun sort< (as)
  (declare #.OPT
           (inline sort)
           ((simple-array int32 (*)) as))
  (sort as #'<))

(defun sort> (as)
  (declare #.OPT
           (inline sort)
           ((simple-array int32 (*)) as))
  (sort as #'>))

(defun main ()
  (declare #.OPT)
  (let* ((n (read))
         (k (read))
         (as (make-array n :element-type 'int32))
         (as+ (make-array n :fill-pointer 0 :element-type 'int32))
         (as- (make-array n :fill-pointer 0 :element-type 'int32)))
    (declare (uint31 n k))
    (dotimes (i n)
      (let ((a (read-fixnum)))
        (setf (aref as i) a)
        (if (>= a 0)
            (vector-push a as+)
            (vector-push a as-))))
    (let ((as+< (sort< (coerce as+ '(simple-array int32 (*)))))
          (as-< (sort< (coerce as- '(simple-array int32 (*)))))
          (as+> (sort> (coerce as+ '(simple-array int32 (*)))))
          (as-> (sort> (coerce as- '(simple-array int32 (*))))))
      (declare ((simple-array int32 (*)) as+< as-< as+> as->))
      (labels ((calc (pivot threshold)
                 (declare (int32 pivot)
                          (fixnum threshold))
                 (let ((res 0))
                   (declare (uint62 res))
                   (cond ((and (>= pivot 0) (>= threshold 0))
                          (incf res (the uint31 (bisect-right as+< threshold pivot)))
                          (incf res (length as->)))
                         ((and (>= pivot 0) (< threshold 0))
                          (incf res (the uint31 (bisect-right as-< threshold pivot))))
                         ((and (< pivot 0) (>= threshold 0))
                          (incf res (the uint31 (bisect-right as-> threshold pivot)))
                          (incf res (length as+>)))
                         ((and (< pivot 0) (< threshold 0))
                          (incf res (the uint31 (bisect-right as+> threshold pivot)))))
                   res))
               (calc-count (threshold)
                 (declare (fixnum threshold))
                 (let ((res 0))
                   (declare (uint62 res))
                   (sb-int:dovector (a as)
                     (incf res (calc a threshold)))
                   (sb-int:dovector (a as)
                     (when (< (* a a) threshold)
                       (decf res)))
                   (setq res (ash res -1))
                   res)))
        (sb-int:named-let bisect ((ng most-negative-fixnum) (ok most-positive-fixnum))
          (declare (fixnum ng ok))
          (if (<= (- ok ng) 1)
              (println ok)
              (let ((mid (floor (+ ng ok) 2)))
                (if (>= (calc-count mid) k)
                    (bisect ng mid)
                    (bisect mid ok)))))))))

#-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 "powershell.exe" '("-Command" "Get-Clipboard") :output out :search t)))

#+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 3
3 3 -4 -2
"
    "-6
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "10 40
5 4 3 2 -1 0 0 0 0 0
"
    "6
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "30 413
-170202098 -268409015 537203564 983211703 21608710 -443999067 -937727165 -97596546 -372334013 398994917 -972141167 798607104 -949068442 -959948616 37909651 0 886627544 -20098238 0 -948955241 0 -214720580 277222296 -18897162 834475626 0 -425610555 110117526 663621752 0
"
    "448283280358331064
")))


(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
           ;; enclose the form with VALUES to avoid being captured by LOOP macro
           #\# #\> (lambda (s c p) (declare (ignore c p)) `(values ,(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
(declaim (inline bisect-left))
(defun bisect-left (target value &key (start 0) end (order #'<) (key #'identity))
  "TARGET := vector | function (taking an integer argument)
ORDER := strict order

Analogue of lower_bound() of C++ or bisect_left() of Python: Returns the
smallest index (or input) i that fulfills TARGET[i] >= VALUE, where '>=' is the
complement of ORDER. In other words, this function returns the leftmost index at
which VALUE can be inserted with keeping the order. Therefore, TARGET must be
monotonically non-decreasing with respect to ORDER.

- This function returns END if VALUE exceeds TARGET[END-1].
- The range [START, END) is half-open.
- END must be explicitly specified if TARGET is function.
- KEY is applied to each element of TARGET before comparison."
  (declare (function key order)
           (integer start)
           ((or null integer) end))
  (macrolet
      ((frob (accessor &optional declaration)
         `(progn
            (assert (<= start end))
            (if (= start end) end
                (labels
                    ((%bisect-left (left ok)
                       ;; TARGET[OK] >= VALUE always holds (assuming
                       ;; TARGET[END] = +infinity)
                       ,@(when declaration (list declaration))
                       (let ((mid (ash (+ left ok) -1)))
                         (if (= mid left)
                             (if (funcall order (funcall key (,accessor target left)) value)
                                 ok
                                 left)
                             (if (funcall order (funcall key (,accessor target mid)) value)
                                 (%bisect-left mid ok)
                                 (%bisect-left left mid))))))
                  (%bisect-left start end))))))
    (etypecase target
      (vector
       (let ((end (or end (length target))))
         (frob aref (declare ((integer 0 #.most-positive-fixnum) left ok)))))
      (function
       (assert end () "Requires END argument if TARGET is a function.")
       (frob funcall)))))

(declaim (inline bisect-right))
(defun bisect-right (target value &key (start 0) end (order #'<) (key #'identity))
  "TARGET := vector | function (taking an integer argument)
ORDER := strict order

Analogue of upper_bound() of C++ or bisect_right() of Python: Returns the
smallest index (or input) i that fulfills TARGET[i] > VALUE. In other words,
this function returns the rightmost index at which VALUE can be inserted with
keeping the order. Therefore, TARGET must be monotonically non-decreasing with
respect to ORDER.

- This function returns END if VALUE >= TARGET[END-1].
- The range [START, END) is half-open.
- END must be explicitly specified if TARGET is function.
- KEY is applied to each element of TARGET before comparison."
  (declare (function key order)
           (integer start)
           ((or null integer) end))
  (macrolet
      ((frob (accessor &optional declaration)
         `(progn
            (assert (<= start end))
            (if (= start end)
                end
                (labels
                    ((%bisect-right (left ok)
                       ;; TARGET[OK] > VALUE always holds (assuming
                       ;; TARGET[END] = +infinity)
                       ,@(when declaration (list declaration))
                       (let ((mid (ash (+ left ok) -1)))
                         (if (= mid left)
                             (if (funcall order value (funcall key (,accessor target left)))
                                 left
                                 ok)
                             (if (funcall order value (funcall key (,accessor target mid)))
                                 (%bisect-right left mid)
                                 (%bisect-right mid ok))))))

                  (%bisect-right start end))))))
    (etypecase target
      (vector
       (let ((end (or end (length target))))
         (frob aref (declare ((integer 0 #.most-positive-fixnum) left ok)))))
      (function
       (assert end () "Requires END argument if TARGET is a function.")
       (frob funcall)))))

(declaim (ftype (function * (values fixnum &optional)) read-fixnum))
(defun read-fixnum (&optional (in *standard-input*))
  "NOTE: cannot read -2^62"
  (macrolet ((%read-byte ()
               `(the (unsigned-byte 8)
                     #+swank (char-code (read-char in nil #\Nul))
                     #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\Nul) nil))))
    (let* ((minus nil)
           (result (loop (let ((byte (%read-byte)))
                           (cond ((<= 48 byte 57)
                                  (return (- byte 48)))
                                 ((zerop byte) ; #\Nul
                                  (error "Read EOF or #\Nul."))
                                 ((= byte #.(char-code #\-))
                                  (setf minus t)))))))
      (declare ((integer 0 #.most-positive-fixnum) result))
      (loop
        (let* ((byte (%read-byte)))
          (if (<= 48 byte 57)
              (setq result (+ (- byte 48)
                              (* 10 (the (integer 0 #.(floor most-positive-fixnum 10))
                                         result))))
              (return (if minus (- result) result))))))))

(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))
         (k (read))
         (as (make-array n :element-type 'int32))
         (as+ (make-array n :fill-pointer 0 :element-type 'int32))
         (as- (make-array n :fill-pointer 0 :element-type 'int32)))
    (dotimes (i n)
      (let ((a (read-fixnum)))
        (setf (aref as i) a)
        (if (>= a 0)
            (vector-push a as+)
            (vector-push a as-))))
    (let ((as+< (sort (coerce as+ '(simple-array int32 (*))) #'<))
          (as-< (sort (coerce as- '(simple-array int32 (*))) #'<))
          (as+> (sort (coerce as+ '(simple-array int32 (*))) #'>))
          (as-> (sort (coerce as- '(simple-array int32 (*))) #'>)))
      (declare ((simple-array int32 (*)) as+< as-< as+> as->))
      (labels ((calc (pivot threshold)
                 (declare (int32 pivot)
                          (fixnum threshold))
                 (let ((res 0))
                   (cond ((and (>= pivot 0) (>= threshold 0))
                          (incf res (bisect-right as+< threshold
                                                  :key (lambda (a) (* (the int32 a) pivot))))
                          (incf res (length as->)))
                         ((and (>= pivot 0) (< threshold 0))
                          (incf res (bisect-right as-< threshold
                                                  :key (lambda (a) (* (the int32 a) pivot)))))
                         ((and (< pivot 0) (>= threshold 0))
                          (incf res (bisect-right as-> threshold
                                                  :key (lambda (a) (* (the int32 a) pivot))))
                          (incf res (length as+>)))
                         ((and (< pivot 0) (< threshold 0))
                          (incf res (bisect-right as+> threshold
                                                  :key (lambda (a) (* (the int32 a) pivot))))))
                   ;; (dbg pivot threshold res)
                   res))
               (calc-count (threshold)
                 #>threshold
                 (let ((res 0))
                   (sb-int:dovector (a as)
                     (incf res (calc a threshold)))
                   (sb-int:dovector (a as)
                     (when (< (* a a) threshold)
                       (decf res)))
                   (setq res (ash res -1))
                   res)))
        (sb-int:named-let bisect ((ng most-negative-fixnum) (ok most-positive-fixnum))
          (if (<= (- ok ng) 1)
              (println ok)
              (let ((mid (floor (+ ng ok) 2)))
                (if (>= (calc-count mid) k)
                    (bisect ng mid)
                    (bisect mid ok)))))
        ))))

#-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 "powershell.exe" '("-Command" "Get-Clipboard") :output out :search t)))

#+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 3
3 3 -4 -2
"
    "-6
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "10 40
5 4 3 2 -1 0 0 0 0 0
"
    "6
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "30 413
-170202098 -268409015 537203564 983211703 21608710 -443999067 -937727165 -97596546 -372334013 398994917 -972141167 798607104 -949068442 -959948616 37909651 0 886627544 -20098238 0 -948955241 0 -214720580 277222296 -18897162 834475626 0 -425610555 110117526 663621752 0
"
    "448283280358331064
")))


Score : 100 points

Problem Statement

Having learned the multiplication table, Takahashi can multiply two integers between 1 and 9 (inclusive) together. He cannot do any other calculation.

Given are two integers A and B.

If Takahashi can calculate A \times B, print the result; if he cannot, print -1 instead.

Constraints

1 \leq A \leq 20

1 \leq B \leq 20

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B

Output

If Takahashi can calculate A \times B, print the result; if he cannot, print -1.

Sample Input 1

2 5

Sample Output 1

10

2 \times 5 = 10.

Sample Input 2

5 10

Sample Output 2

-1

5\times 10 = 50, but Takahashi cannot do this calculation, so print -1 instead.

Sample Input 3

9 9

Sample Output 3

81


(defun prob-a (lst)
  (if (and (< (car lst) 10)
           (< (cadr lst) 10))
      (* (car lst)
         (cadr lst))
      -1))

(format t "~a~%" (prob-a (list (read) (read))))


(defvar A (read))
(defvar B (read))

(defun compare (v)
  (if (and (> v 0) (< v 10))
      t
      nil))

(if (and (compare A) (compare B))
    (princ (* A B))
    (princ -1))


#!/usr/local/Cellar/sbcl/1.5.7/libexec/bin/sbcl --script
# FASL
  compiled from "test.lisp"
  using SBCL version 1.5.7
����X86-64N����������1.5.7.���(GENCGC SB-PACKAGE-LOCKS SB-THREAD SB-UNICODE)M	READ7��7�M
FORMATe~a~%M<=&#	7&#	7

	M*7
(
	8?>@


(defun kake ()
  (let* ((a (read))
        (b (read))
        (c (* a b)))
    (if (or (> a 9) (> b 9))
        (setf c -1))
    (format t "~d" c)))

(kake)


;; -*- 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* ((a (read))
         (b (read)))
    (if (and (<= 1 a 9) (<= 1 b 9))
        (println (* a b))
        (println -1))))

#-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 "2 5
"
    "10
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "5 10
"
    "-1
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "9 9
"
    "81
")))